这是前端代码 <!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>表单与PHP交互</title>
</head>
<body>
<!--<form action="http://localhost:63342/htdocs/Service.php" method="get">-->
<form action="http://localhost:63342/htdocs/Service.php" method="post">
用户名:<input type="text" name="name">
密 码:<input type="password" name="password">
<br/>
<input type="submit" value="提交">
</form>
</body>
</html>这是php代码
<?php
//echo "用户名:".$_GET['name']."<br>密码:".$_GET['password'];
echo "用户名:".$_POST['name']."<br>密码:".$_POST['password'];
这是报错Notice: Undefined index: name in C:\xampp\htdocs\Service.php on line 3Notice: Undefined index: password in C:\xampp\htdocs\Service.php on line 3
用户名:
密码:
<html>
<head lang="en">
<meta charset="UTF-8">
<title>表单与PHP交互</title>
</head>
<body>
<!--<form action="http://localhost:63342/htdocs/Service.php" method="get">-->
<form action="http://localhost:63342/htdocs/Service.php" method="post">
用户名:<input type="text" name="name">
密 码:<input type="password" name="password">
<br/>
<input type="submit" value="提交">
</form>
</body>
</html>这是php代码
<?php
//echo "用户名:".$_GET['name']."<br>密码:".$_GET['password'];
echo "用户名:".$_POST['name']."<br>密码:".$_POST['password'];
这是报错Notice: Undefined index: name in C:\xampp\htdocs\Service.php on line 3Notice: Undefined index: password in C:\xampp\htdocs\Service.php on line 3
用户名:
密码:
a页面是表单 提交到action="b.php"
b页面写echo "用户名:".$_POST['name']."<br>密码:".$_POST['password'];
接到数据之后用isset判断一下
isset($_POST['name'])?$_POST['name']:'';
$user_name = '';
$user_password = '';
if(isset($_POST['name'])){
$user_name = $_POST['name'];
}
if(isset($_POST['password'])){
$user_password = $_POST['password'];
}
echo "用户名:".$user_name."<br>密码:".$user_password;