我已经尝试并尝试创建一个表单来更改您的密码,但我似乎无法正确设置,请帮助!现在每次我尝试更改密码时都告诉我“查询失败”,还有其他变量,例如用户名,名字,但是用户只被允许更改他们的密码,所以我只包括UPDATE members SET 'passwd'
- 这些是某人最初注册时创建的变量,members(firstname, username, login, passwd, ip) VALUES('$fname','$uname','$login','".md5($_POST['password'])."','$ip')";
<?php
require_once('config.php');
require_once('auth.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$password = clean($_POST['password']);
$retpassword = clean($_POST['retpassword']);
//Input Validations
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();
}
//Create UPDATE query
$qry = "UPDATE members SET 'passwd' = '".md5($_POST['password'])."' WHERE login = '{$_SESSION['username']}'";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: changed.php");
exit();
}else {
die("Query failed");
}
?>