dtpw54085 2014-02-20 16:02
浏览 15
已采纳

问题插入行MySQL,没有MySQL错误

I have the following php script snippet:

try{
  $con = new PDO("mysql:host=$host;dbname=$databaseName;charset=utf8",$user,$pass);
  $con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $dat = $_REQUEST['dat'];
  $poll = $dat[0];
  $date = $dat[1];
  $zip = $dat[2];
  $answer = $dat[3];

  $q = $con->prepare("INSERT INTO votes (poll_id, date, location, answers) VALUES (:poll, :date, :zip, :answer)");
  $q->bindParam(':poll', $poll, PDO::PARAM_INT);
  $q->bindParam(':date', $date, PDO::PARAM_STR);
  $q->bindParam(':zip', $zip, PDO::PARAM_STR);
  $q->bindParam(':answer', $answer, PDO::PARAM_STR);

  if ($q->execute){
     echo "worked";
  } else {
     echo "didn't work";
  }
}catch(PDOException $e){
  echo $e->getMessage();
}

Every time I try and run this script, I get an internal server error (500). There is no echo, no error message, nothing. When I remove the error handling, I get 200, but the "didn't work" message.

Please help!

EDIT: Added ini_set("display_errors",1); to top of page. Some reason 500 error no longer occurs, but still getting "didn't work".

  • 写回答

1条回答 默认 最新

  • douduonang3169 2014-02-20 16:08
    关注

    try to change if ($q->execute){ to if ($q->execute()){

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

报告相同问题?

悬赏问题

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