<center>
<h3>登录界面</h3>
<form action="#" id="form1" name="form1" method="post">
用户名:<input type="text" id="username" >
密 码:<input type="password" id="pwd"><br><br>
<input type="submit" name="submit" value="注册">
<input type="reset" name="reset" value="重置">
</form>
</center>
<?php
include_once ("conn.php");$username=$_POST["username"];
$pwd=$_POST["pwd"];
if ($username!="" && $pwd!="")
 {
$pdo->exec("insert into user (username,pwd) values('".$username."','".$pwd."')");
echo "注册成功";
 }

else 
{
echo "用户名或者密码不能为空";
}
 
?>   

解决方案 »

  1.   

    action="#"   改成空看看!
      

  2.   

    <center>
    <h3>登录界面</h3>
    <form action="#" id="form1" name="form1" method="post">
    <!-- 这里要加上name属性,否则$_POST中没有对应的值 -->
    用户名:<input type="text" id="username" name="username"> 
    密 码:<input type="password" id="pwd" name="pwd"><br>
    <br>
    <input type="submit" name="submit" value="注册">
    <input type="reset" name="reset" value="重置">
    </form>
    </center>
    <?php
    include_once ("conn.php");$username=$_POST["username"];
    $pwd=$_POST["pwd"];
    if ($username!="" && $pwd!=""){
    $pdo->exec("insert into user (username,pwd) values('".$username."','".$pwd."')");
    echo "注册成功";
    } else {
    echo "用户名或者密码不能为空";
    }
    ?>
      

  3.   

    $_POST['field'] field 对应的就是input中的name属性
      

  4.   

    get和post方法是根据name来获取提交的表单信息的