今天完成了PHP实验三:
1.要求编写一个静态表单页面和一个 PHP 动态网页,将表单的值在动态网页中显示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>个人信息</title> </head> <body> <form action='info.php' method="get"> <table border="0"> <tr> <td> 姓名:<input type="text" required name="user"> </td> </tr> <tr> <td> 性别:<input type="radio" name="sex" value="男">男  <input type="radio" name="sex" value="女">女 </td> </tr> <tr> <td> <input type="submit" value="提交"> <input type="reset" value="重新提交"> </td> </tr> </table> </form> </body> </html>
<?php $user=$_GET["user"]; $sex=$_GET["sex"]; echo "$user 同学,欢迎你访问本页面<br>"; echo "您是一名$sex 生"; ?>
2.在PHP中嵌入JavaScript代码:
例:
echo "<script type=text/javascript>alert('用户名不能为空!')</script>";
3.计算从 1 开始到你指定的数的累加和,指定数字由用户自己输入,
<?php if (!empty($_POST)){ $num=$_POST["num"]; $i=1; $sum=0; for ($i=1;$i<=$num;$i++){ $sum=$sum+$i; } echo "<script type=text/javascript>alert('1+2+...+$num=$sum')</script>"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>计算累加和</title> </head> <body> <form action="" method="post"> <p style="color: #146C9C"> <h3>计算累加和</h3> <br> </p> <p> 1+2+...+ <input type="text" name="num"> <input type="submit" value="提交"> </p> </form> </body> </html>