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

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用