douxieshang5577 2019-05-01 13:05
浏览 35
已采纳

php中的mysql更新不会更新错误500

Here is my code.

    $rs = $db->query('UPDATE shorturl SET originalUrl = :originalUrl, status = :status, expiryDate=null, shortUrlFolder=:shortUrlFolder WHERE id = :id', array('originalUrl'    => $original_url, 'status'         => $status, 'shortUrlFolder' => $shortUrlFolder, 'id'             => $urlId));

If i change "status = :status" to "status = active" or "status = 'active'" I get a 500 error from my page when i run it, why is this am i getting the string wrong ? if i change back to "status = :status" it all works.

  • 写回答

1条回答 默认 最新

  • dongxiezhuo8852 2019-05-01 14:13
    关注

    Two things.

    1) string constants in SQL need to be surrounded by single-quote characters. So use status='active' rather than status=active.

    2) 500 errors often result from error returns from database statements, possibly due to incorrectly formed queries. You should check for errors ... something like this:

    $rs = $db->query('...
    if (!$rs) {
          die "query failed: " . $db->error;
    }
    

    It's good practice always to check for these errors.

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条