更新表无效

时间:2017-10-10 22:29:51

标签: php sql prepared-statement

我制作此代码以检查用户是否连续5次输入了错误的密码。该代码的工作原理除外,它更新了“被阻止”的值。在表格'用户'。我检查了$ stmt是否有错误,但没有。

我无法找出我做错的事情

以下是代码:

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$username = "pfrolov";
require "connectDB.php";
$stmt1 = $conn->prepare("SELECT `username`, `time`, `succes`  FROM 
`loginAttempts` WHERE `username`= ? ORDER BY `time` DESC LIMIT 5");
$stmt1->bind_param('s', $username);
$stmt1->execute();
$stmt1->bind_result($username, $time, $succes);
$stmt1->store_result();
if($stmt1->num_rows == 5) {
    $i = 0;
    while($stmt1->fetch()) {
      echo $username ." ". $time ." ".$succes. "<br>";
      if($succes == 0){
        $i++;
      }         
    }
    echo $i;
    if($i == 5){
      echo 'blocked';
      $stmt = $conn->prepare("UPDATE `users` SET `blocked`=? WHERE 
`username`=?");
      $stmt->bind_param('is', $blocked, $username);
      $stmt->execute();
      return $stmt->affected_rows;
      $stmt->close();
    }
$stmt1->close(); 
}
?>

由于

1 个答案:

答案 0 :(得分:0)

您没有定义$ blocked:

/boats/{123}/comments
/cars/{123}/comments