UPDATE显示错误但成功

时间:2016-04-20 09:30:12

标签: php mysql mysqli

我尝试更新表并显示SQL语法错误,但它正确更新了表。我不确定其背后的原因是什么,我只是不想完全关闭错误。

Error: 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

这是功能:

function logTime($time){
      $sql1 = mysqli_query($this->con, "UPDATE `pilots` SET `active`='0',`total_time`='".$time."' WHERE username = '".$this->whoMe()."'");

      if (mysqli_query($this->con, $sql1)) {
             header('Location: index.php?pausedtime');
             die();
      }
      else {
            echo "Error: " . $sql1 . "<br>" . mysqli_error($this->con);
      }
}

1 个答案:

答案 0 :(得分:4)

那是因为您使用mysqli_query()两次...... $sql1行应该足够了。试试这个:

function logTime($time){
      $sql1 = mysqli_query($this->con, "UPDATE `pilots` SET `active`='0',`total_time`='".$time."' WHERE username = '".$this->whoMe()."'");

      if($sql1){
             header('Location: index.php?pausedtime');
             die();
      } else {
            echo "Error: " . $sql1 . "<br>" . mysqli_error($this->con);
      }
}

另请注意,出于安全原因(至少),此类查询prepared statements执行。