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

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)