表格不是POSTing值

时间:2013-08-07 18:44:46

标签: php html forms

形式:

<form id="register" method="POST" action="pro/register.php">
    <input type="text" maxlength="30" placeholder="Username" id="user" /><br />
    <input type="email" maxlength="64" placeholder="Email" id="email" /><br />
    <input type="password" placeholder="Password" id="pass1" /><br />
    <input type="password" placeholder="Confirm Password" id="pass2" /><br />
    <input type="submit" value="Register" id="submit_register" />
</form>

pro/register.php页面

$user = $_POST['user'];
$email = $_POST['email'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];

//Debug only
echo "<strong>Details:</strong><br>";
echo $user.", ".$email.", ".$pass1.", ".$pass2."<br>";

if($pass1!==$pass2){
    header('Location:../login.php?alert=pass');
    exit;
}

$hash = hash('sha256', $pass);

include "../inc/functions.php";

$salt = createSalt();
$hash = hash('sha256', $salt . $hash);

include "../inc/connect.php";

$stmt = $dbh->prepare("INSERT INTO `users` 
                (`username`,`email`,`password`,`salt`,`pic`) 
                VALUES (:username,:email,:password,:salt,:pic)");
$stmt->bindParam(':username',$user);
$stmt->bindParam(':email',$email);
$stmt->bindParam(':password',$hash);
$stmt->bindParam(':salt',$salt);
$stmt->bindParam(':pic',$pic);
$stmt->execute();
$dbh=NULL;

header('Location:../login.php?alert=newreg');

发布表单时的输出:

Details:
, , , 

2 个答案:

答案 0 :(得分:13)

<input type="text" maxlength="30" placeholder="Username" id="user" name="user"/><br />

尝试添加名称字段。

答案 1 :(得分:4)

您必须在表单输入中包含“name”属性,这是确定$ _POST中值的位置。