(1)sy3_1.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP交互界面演示</title>
</head>
<?php
$XH="18001";
echo "<table width=200 border=1 align=center color=red>";
echo "<tr><td>学号</td><td>姓名</td><td>性别</td></tr>";
echo "<tr><td>$XH</td><td>张三</td><td>男</td></tr>";
echo "<tr><td>18002</td><td>丽丽</td><td>女</td></tr>";
echo "<tr><td>18006</td><td>李四</td><td>男</td></tr>";
echo "<script>alert('学生不存在!')</script>";
?>
</html>
(2)sy3_2.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>在HTML中嵌入PHP</title>
</head>
<body>
<?php
$XH="18002";
?>
学号:<input type= "text" name="XH" value="<?php echo $XH;?>"/><br/>
<?php
echo "<form>性别:<input type=text name=sex value=男 /></form>"
?>
</body>
</html>
(3)sy3_3.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<form>
<table border="1" align="center" cellspacing="0">
<tr><td colspan="2" align="center" bgcolor="#999999" >用户登录表单</td></tr>
<tr><td>登录名:</td><td><input type="text" name="username"/></td></tr>
<tr><td>密码:</td><td><input type="password" name="password"/></td></tr>
<tr colspan="2" align="center" >
<td>
<input type="submit" name="submit1" value="登录">
<input type="reset" name="submit2" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit1'])){
$username= $_POST['username'];
$password=$_POST['password'];
if($username=="admin"&&$password=="123456"){
echo "<script>alert('登录成功!');</script>";
}else{
echo "<script>alert('登录失败!');</script>";
}
}
?>
(4)sy3_4.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<div>
<font size="4" color="blue" face="黑体">
计算机累计和
</font>
</div>
<form action="" method="post" >
1+2+3+.....+<input type="text" name="num" size="5">
<input type="submit" name="submit" value="计算">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$num=$_POST['num'];
$i=0;
$sum=0;
if($num<=2){
echo "<script>alert('输入的数据必须大于2!');</script>";
}else{
while($i<=$num){
$sum=$sum+$i;
$i++;
}
echo "<script>alert('1+2+....+$num=$sum');</script>";
}
}
?>
(5)sy3_5.php
<?php
function my_sort($array){
for($i=0;$i<count($array);$i++){
for($j=$i+1;$j<count($array);$j++){
if($array[$i]>$array[$j]){
$temp = $array[$j];
$array[$j] = $array[$i];
$array[$i] = $temp;
}
}
}
return $array;
}
echo "请输入需要排序的数据:<br/>";
echo "<form method=post>";
for($i=1;$i<6;$i++){
echo "<input type='text' name='stu[]' size='5'>";
if($i<5)
echo "-";
}
echo "<input type='submit' name='bt' value='提交' >";
echo "</form>";
if(isset($_POST['bt']){
$stu=$_POST['stu'];
$arr_stu=my_sort($stu);
echo "排序后的数据如下所示:<br/>";
while(list($key,$value)=each($arr_stu)){
echo $value."<br/>";
}
}
?>
(6)sy3_6.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SY3_1</title>
</head>
<body>
<?php
for($i=1;$i<=9;$i++){
for($j=1;$j<=$i;$j++){
echo "$i*$j=".$i*$j." "." "." "." ";
if($j==$i){echo "<br/>";}
}
}
?>
</body>
</html>
(7)sy3_7.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
table.td:200px;
border:1px solid;
text-align:center;
margin:auto;
</style>
<title>表格输出</title>
</head>
<body>
<?php
$i=0;
echo "<table>";
while($i<5)
{
echo "<tr>";
for($j=1;$j<5;$j++)
{
echo "<td>".$i.$j."</td>";
}
echo "</tr>";
$i++;
}
echo "<table>";
?>
</body>
</html>
(8)sy3_8.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<form action="" method="post" >
<p>以下属于WEB开发语言的有哪几种?</p>
<input type= "checkbox" name=answer[] value="C语言"/>C语言<br/>
<input type= "checkbox" name=answer[] value="PHP"/>PHP<br/>
<input type= "checkbox" name=answer[] value="FLASH"/>FLASH<br/>
<input type= "checkbox" name=answer[] value="ASP"/>ASP<br/>
<input type= "checkbox" name=answer[] value="JSP"/>JSP<br/>
<input type= "submit" name="botton" value="提交"/><br/>
</form>
<?php
if(isset($_POST["botton"])){
$answer=@$_POST["answer"];
if(!$answer){
echo "<script>alert('请选择答案!')</script>";
}
$num=count($answer);
$anw="";
for($i=0;$i<$num;$i++){
$anw=$anw*$answer[$i];
}
if($anw=="PHPASPJSP"){
echo "<script>alert('回答正确!')</script>";
}else{
echo "<script>alert('回答错误!')</script>";
}
}
?>
</body>
</html>