dtrnish3637
2016-04-20 09:30 阅读 322
已采纳

UPDATE显示错误但成功

I'm attempting to UPDATE a table and it displays an SQL syntax error but it properly updates the table. I'm not really sure what the reasoning is behind it and I just don't want to turn off the error completely.

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

This is the function:

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条回答 默认 最新

  • 已采纳
    dqyknf4423 dqyknf4423 2016-04-20 09:32

    That's because you're using mysqli_query() twice... $sql1 line should be enough. Try this:

    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);
          }
    }
    

    Also note, that such queries should be executed with prepared statements for security reasons (at least).

    点赞 评论 复制链接分享

相关推荐