douoyou3348 2019-04-05 17:27
浏览 36
已采纳

更新查询不能在php和phpmyadmin中工作

i'm trying to create a multiple photo uploading script in php. All seems to be working fine except the update query. tried updating it manually in phpmyadmin and the problem of not updating persists don't know what to do can any experts help me solve this problem.

here is the update query:

 try {
          $sql1="update photos 
          set 
          filename='{$db_file_name}',
          upload_date=now() where user='{$_SESSION['id']}' ";
          $st1=$conn->prepare($sql1);
          $st1->execute();

     } 
  catch (Exception $exc) {
          echo $exc->getMessage();   
     }
  • 写回答

2条回答 默认 最新

  • dongtuhe0506 2019-04-05 17:44
    关注

    user is a keyword, better use backticks around it. See: https://dev.mysql.com/doc/refman/8.0/en/keywords.html

     try {
         $sql = "UPDATE `photos` 
                 SET `filename` = :filename, 
                     `upload_date` = NOW() 
                 WHERE `user` = :sess_id";
         $stmt = $conn->prepare($sql);
         $stmt->bindValue(":sess_id", $_SESSION['id']);
         $stmt->bindValue(":filename", $db_file_name);
         $stmt->execute();
    } catch (....) {
       ....
    }
    

    Perhaps better still, don't use keywords as column names, try userId.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?