2014-04-01 62 views
-1

我想使用html表單將密碼重置爲散列md5密碼。我將包括我所有的代碼。當我提交表單時,我收到一個空白屏幕。我是初學者,請記住這一點。我檢查myphpadmin並且散列的密碼不會改變。使用更新md5密碼重置密碼的問題

<html> 
<head><title> Administrator reset password page</title></head> 
<body> 
<form action="forgotpass.php" method="post"> 
<table> 
<tr><td>User Name:</td><td><input type="text" name="password" /></td></tr> 
<tr><td>Password:</td><td><input type="text" name="user" /></td></tr> 
<tr><td colspan="2" align="center"><input type="submit" value="Reset Password"/></td>  </tr> 
</table> 
</form> 
</body> 
</html> 

<?php 
include "connect.php" 
$tmpPass = $_POST['password']; 
$tmpuser= $_POST['user']; 


$tmpPass = md5($tmpPass); 


$sql = mysql_query("UPDATE employee set pass = $tmpPass WHERE usr = $tmpuser"); 

// Performs the $sql query on the server to insert the values 
if ($conn->query($sql) === TRUE) { 
    echo 'Password Has Been Reset Successfully'; 



/* 
$email_message.= "Hello "; 
$email_message.= "User with username: " .$tmpUser. "\n"; 
$email_message.= "Your New password: " .$_POST['password']. "\n"; 
$email_to = "[email protected]"; 
$email_subject = "Registration"; 
*/ 

else { 
echo 'Error: '. $conn->error; 
} 

$conn->close(); 
?> 
+1

爲什麼要執行兩次相同的查詢? –

+1

你絕對不想使用md5來散列密碼。見http://php.net/password_hash你應該怎麼做。 – Mike

+0

你的表單變量Name ='「password」'和Password =''user「'也是錯誤的。請至少通過您的代碼來省略基本錯誤。 – JBES

回答

0

你錯過了周圍的字符串值引號:

$sql = mysql_query("UPDATE employee set pass = '$tmpPass' WHERE usr = '$tmpuser'"); 

另外,爲什麼你運行你的查詢第二次?

// Performs the $sql query on the server to insert the values 
if ($conn->query($sql) === TRUE) { // <-- HERE 
    echo 'Password Has Been Reset Successfully'; 

$sql變量將包含您的查詢的布爾結果,你需要檢查的變量是真實的,而不是再次運行查詢:

if($sql === true) { 
    echo 'Password Has Been Reset Successfully'; 
+0

我認爲<$conn->查詢($ sql)== true檢查,看看過程是否成功完成並給出回聲。 – user3487244

+0

您可以使用'mysql_effected_rows()'作爲 –