无法得到post过来的值
<form method="post" action="http://localhost/secret.php" >
<table border="1">
<tr>
<th>Username</th>
<td><input type="text" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="text" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Log In" /></td>
</tr>
</table>
</form>
初学php,为什么上面无法把name和password传到secret.php里,导致每次都输出Please input an effective username and password?
//secret.php
<?php
//Create short names for variables
if($_POST['name']==''&&$_POST['password']=='')
{
//Visitor need to enter a name and password
echo '<h1>Please input an effective username and password</h1>';
}
elseif($_POST['name']=='root'&&$_POST['password']=='123')
{
echo '<h1>Welcome to the New World!</h1>';
}
else
{
echo '<h1>You are not welcome!</h1>';
}
?>
------解决方案--------------------
需要为input控件增加name属性,只有这样,浏览器才会把值提交到服务器
<th>Username</th>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="text" name="password" /></td>