2

形式:

<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:
, , , 
4

2 回答 2

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

尝试添加名称字段。

于 2013-08-07T18:46:17.163 回答
5

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

于 2013-08-07T18:46:57.357 回答