2013-08-07 89 views
1

表:形式不張貼值

<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: 
, , , 
+0

如果給元素添加'name'會怎樣? – Icarus

+1

您沒有爲任何輸入設置名稱... – Neal

+0

謝謝您指出這一點。我認爲它採用了「ID」值。 – Ben

回答

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

嘗試添加名稱字段。

+0

嗯謝謝你,我以爲它拿了ID。非常感謝 – Ben

+1

@BenPearlKahan作爲一般規則,使用Ids for javascript/css和Names for forms – Basic

4

您必須在表單輸入中包含'name'屬性,這是確定值在$ _POST中的位置的原因。