SQL查询失败[密码更改]

时间:2013-06-05 06:55:55

标签: mysql sql passwords

我正在我的网站上工作,我正在尝试创建一个允许他们更改密码的设置页面,但每次我尝试更改密码时都会显示Query failed,如果你能发现问题,那将是一个很好的帮助;

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 个答案:

答案 0 :(得分: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']."";