gpt4 book ai didi

php - MYSQL/PHP 选择

转载 作者:行者123 更新时间:2023-11-29 05:24:41 26 4
gpt4 key购买 nike

我有 2 个表:

  • newpw_ask

    email
    code
  • 用户

    id
    username
    password
    email
    sid
    newpw_code

我有这个 PHP 代码:

$code = $_POST['code2'];
$email = mysql_query("SELECT email FROM pw_ask WHERE code='$code'");

if ($pass == $pass2) {
if ($email) {
$pass3 = md5($pass);

mysql_query("UPDATE users SET password='$pass3' WHERE email='$email'");
mysql_query("UPDATE users SET newpw_code='' WHERE email='$email'");
mysql_query("DELETE FROM pw_ask WHERE code='$code'");

header("Location: index.php?ret=pw");
} else {
echo 'Wrong code';
}
}

只执行了这个查询:

mysql_query("DELETE FROM pw_ask WHERE code='$code'");

此外,当我输入正确的代码时,它会显示“错误代码”。

最佳答案

您需要正确选择邮箱:

$sql    = mysql_query("SELECT email FROM pw_ask WHERE code='$code'");
$row = mysql_fetch_array($sql);
$email = $row['email'];

顺便说一句,您还可以在 1 个查询中更新多个字段:

mysql_query("UPDATE users SET password='$pass3' , newpw_code='' where email='$email'");

关于php - MYSQL/PHP 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21683072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com