将数据粘贴到表单中并单击“提交”按钮后,即使粘贴正确的密码,也总是收到错误消息“密码错误”。谁能帮我吗?
<?php
session_start();
include_once 'dbconnect.php';
if (isset($_POST['ulozitzmeny']) && ($_SESSION['user']) && strlen($_SESSION['user']) > 0) {
$first_name = mysql_real_escape_string($_POST['jmeno']);
$last_name = mysql_real_escape_string($_POST['prijmeni']);
$email = mysql_real_escape_string($_POST['email']);
$password = hash('sha512', mysql_real_escape_string($_POST['heslo']));
$res = mysql_query("SELECT password FROM users WHERE username='$_SESSION[user]'");
$row = mysql_fetch_array($res);
if ($password != $row) {
echo" <div id='alerts' class='alert alert-danger'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<strong>Chyba!</strong> Nespávné heslo!
</div>";
} else {
if (mysql_query("UPDATE users SET first_name='$first_name', last_name='$last_name', email='$email' WHERE username = '$_SESSION[user]'")or die(mysql_query)) {
echo" <div id='alerts' class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<strong>Úspěch!</strong> Změny proběhly úspěšně!
</div>";
}
}
}
?>
最佳答案
更改
if ($password != $row) {
至
if ($password != $row[0]) {
关于php - 更新用户信息无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33924099/