表:形式不張貼值
<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:
, , ,
如果給元素添加'name'會怎樣? – Icarus
您沒有爲任何輸入設置名稱... – Neal
謝謝您指出這一點。我認爲它採用了「ID」值。 – Ben