2013-06-05 100 views
0

我正在我的網站上工作,並且正在嘗試創建一個設置頁面,允許他們更改密碼,但是每次我嘗試更改密碼時,它都會顯示Query failed,if你可以發現問題,這將是一個很大的幫助;SQL查詢失敗[密碼更改]

require_once('config.php'); 
require_once('auth.php'); 


$errmsg_arr = array(); 


$errflag = false; 


$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 
if(!$link) { 
    die('Failed to connect to server: ' . mysql_error()); 
} 


$db = mysql_select_db(DB_DATABASE); 
if(!$db) { 
    die("Unable to select database"); 
} 
$password = clean($_POST['password']); 
$retpassword = clean($_POST['retpassword']); 


if($password == '') { 
    $errmsg_arr[] = 'Password missing'; 
    $errflag = true; 
} 
if($retpassword == '') { 
    $errmsg_arr[] = 'Please retype your password'; 
    $errflag = true; 
} 
if(strcmp($password, $retpassword) != 0) { 
    $errmsg_arr[] = 'New passwords do not match!'; 
    $errflag = true; 
} 

//If there are input validations, redirect back to the settings page 
if($errflag) { 
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr; 
    session_write_close(); 
    header("location: settings.php"); 
    exit(); 
} 


$qry = "UPDATE members SET passwd = ".md5($_POST['password'])." WHERE member_id = ".$_SESSION['SESS_MEMBER_ID'].""; 
$result = @mysql_query($qry); 


if($result) { 
    header("location: changed.php"); 
    exit(); 
}else { 
    die("Query failed"); 
} 
?> 
+1

使用'mysql_error()'來找出哪裏出了問題。 –

+0

@皮卡웃謝謝! – user2331568

回答

0

在黑暗中只是一個鏡頭,因爲我不知道該錯誤信息,而不是:

$qry = "UPDATE members SET passwd = ".md5($_POST['password'])." WHERE member_id = ".$_SESSION['SESS_MEMBER_ID'].""; 

使用這個(你忘了用單引號密碼):

$qry = "UPDATE members SET passwd = '".md5($_POST['password'])."' WHERE member_id = ".$_SESSION['SESS_MEMBER_ID'].""; 
+0

非常感謝你,對不起,我不知道如何迴應mysql錯誤,這工作。 =] – user2331568

+0

np,用這個'$ query = mysql_query($ sql)或者死(mysql_error())來捕獲錯誤;'' – Stephan