2016-07-26 96 views
0

我正在處理表單和表單處理程序。方法是_POST,我使用PHP來處理它。現在,當我想要處理表格時,它說$username是未定義的。使用POST處理表格

我的表格:

<html> 
    <head> 
    <title>Register</title> 
    <script type="text/javascript" src="includes/register_form_validator.js" ></script> 
    </head> 
    <body> 
    <form method="post" action="includes/register_form_handler.php" name="register_form" > 
     <label for="username" >Username :</label><input placeholder="username" type="text" /><br> 
     <label for="password">Password :</label><input type="password" name="password" /><br> 
     <label for="cpassword">Confirm Password :</label><input type="password" name="cpassword" /><br> 
     <label for="email">E-Mail :</label><input type="email" name="email" onChange="" /><br> 
     <input type="submit" value="Submit" /> 
    </form> 
    </body> 
</html> 

處理程序:

<?php 
// Do a Form Validation , Makes sure that resource is Valid/////////// 
$actual_link = "http://$_SERVER[HTTP_HOST]" . "/dcreview/register.php"; 
if (!isset($_SERVER['HTTP_REFERER'])) { 
    echo "Invalid Form"; 
    exit; 
} else { 
    if ($_SERVER['HTTP_REFERER'] != $actual_link) { 
    echo "Invalid Form"; 
    exit; 
    } 
} 
/////////////////////////////////////////////////////////////////// 
// Processes Form // 
$user = $_POST["username"]; 
$pass = $_POST['password']; 
$email = $_POST['email']; 

password_hash($pass, PASSWORD_BCRYPT); 
?> 
+0

你的代碼似乎沒有提到'$ username',所以你的錯誤不匹配? –

+1

'$ user'!='$ username'你的腳本定義了'$ user' –

+0

感謝大家回答。我想我應該多看兩次我的代碼。這是我的眼睛的錯誤.sorry – GeekyMo

回答

3

這一行替換您的用戶名HTML

<label for="username" >Username :</label><input name="username" placeholder="username" type="text" /><br> 
+0

解釋你改變了什麼! –

+0

我在您的輸入標籤中添加了名稱=「用戶名」,這是缺少檢查$ _POST ['username']; –

3

您的用戶名不具有名稱屬性。使用這個:

<input name="username" placeholder="username" type="text" />