PHP与Web页面的交互

1.form表单默认情况下提交数据的方式为get方式。

2.PHP脚本用来处理表单数据的预定义变量是$_GET,$_POST(区分大小写)

代码示例:(特别注意复选框属性name的时候加数组)

simpleTest.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="simpleForm.php" method="post">
    用户名:<input type="text" name="username"><br>
    密码:<input type="text" name="password"><br>
    <!-- 复选框 -->
     学过的编程语言是:<br>
    <input type="checkbox" name="language[]" value="PHP">php
    <input type="checkbox" name="language[]" value="java">java
    <input type="checkbox" name="language[]" value="C#">C#
    <input type="checkbox" name="language[]" value="C++">C++<br>
    <input type="submit" value="提交" >
</form>
</body>
</html>

simpleFoem.php

<?php
if(!empty($_POST["username"])){
    if($_POST["username"]=="zhangsan"&&$_POST["password"]=="123"){
        echo "欢迎您:".$_POST["username"]."<br/>";
        echo "学过的编程语言:";
        foreach ($_POST["language"] as $value){
            echo  $value;
            
        }
        
    }else {
        echo "用户名密码错误";
    }
}
    
?>

猜你喜欢

转载自www.cnblogs.com/sunxiaoyan/p/9258102.html
今日推荐