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

    点赞 评论 复制链接分享

相关推荐