为什么MySQL查询没有被执行?

时间:2017-11-01 21:55:47

标签: php mysql sql xampp

我正在尝试同时运行两个查询并用分号分隔它们。

$query2 = "UPDATE users SET locked = '1' WHERE id = '13'; 
        UPDATE users SET reset_key = '".$resetKey."' WHERE id = '13';";

这是我的完整代码。我正在尝试为登录表单创建一种强力保护。如果有5次不正确的登录尝试,则该帐户应该锁定并创建随机重置密钥。然后密钥存储在数据库中,这就是查询未被执行的地方。

<?php
$mysqli = new mysqli('localhost', 'x', 'x', 'x');
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}
$result = $mysqli->query("SELECT * FROM `users` WHERE `email` = 'abc@abc.abc'");
$result = $result->fetch_row();
$locked = $result[5];
$resetKey = $result[6];
$attempts = $result[4];


    if ($attempts == NULL) {
        $attempts = 1;
    } elseif ($attempts == '5') {
        /* let's create a random string */
        $letters='abcdefghijklmnopqrstuvwxyz';  // selection of a-z
        for($x=0; $x<3; ++$x){  // loop three times
            $resetKey.=$letters[rand(0,25)].rand(0,9);  // concatenate one letter then one number
        }
        $query2 = "UPDATE users SET locked = '1' WHERE id = '13'; 
        UPDATE users SET reset_key = '".$resetKey."' WHERE id = '13';";
        echo "<p>".$query2."</p>";
        $result2 = $mysqli->query($query2);
    } else {
        $attempts++;
        $query3 = "UPDATE users SET attempts = '".$attempts."' WHERE id = '13'";
        $result3 = $mysqli->query($query3);
    }
?>

0 个答案:

没有答案