我有以下代码:

$userpass = $row->userpass;
$gesamtpass = $pass.$chili;
$pwdata = mysql_query("SELECT MD5('".$gesamtpass."') AS newpass");
$pwk = mysql_fetch_object($pwdata);
$pwkey = $pwk->newpass;

$_POST["email"] = $email;
$_POST["fbuid"] = $fbuid;

if ($userpass == $pwkey){
  $result_update = mysql_query("UPDATE member SET (fbuid = '".mysql_real_escape_string($_POST["fbuid"])."')  WHERE email = '".mysql_real_escape_string($_POST['email'])."'") or die("not possible");}

我不需要这些代码来更新我的数据。

最佳答案

这段代码以更整洁的方式完成了您想要做的事情。当事情出错时,它还输出一些有用的错误消息。显然,您不应该在生产中直接将这些输出给用户,但它将帮助您在开发时调试问题。

// Is this already an MD5 hash?
$userpass = $row->userpass;
// MUCH simpler way to do MD5
$pwkey = md5($pass.$chili);

if ($userpass == $pwkey) { // Compare the passwords
  // If they match, do the query
  $query = "UPDATE member
            SET fbuid = '".mysql_real_escape_string($fbuid)."'
            WHERE email = '".mysql_real_escape_string($email)."'";
  mysql_query($query) or die("MySQL Query Error: ".mysql_error());
} else {
  // They don't match, lets look at the data and find out why
  die("They don't match! $userpass != $pwkey");
}

关于php - SQL UPDATE IF密码正确,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8712294/

10-11 01:27