dtrnish3637 2016-04-20 09:30
浏览 398
已采纳

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 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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码