1

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

2
  • 1
    Turn on your php errors. Add ini_set("display_errors",1); at the top of your file. Commented Feb 20, 2014 at 16:04
  • Added, somehow the 500 error is now gone, but still receiving "didn't work". Commented Feb 20, 2014 at 16:08

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Buy @Alon a beer! Thanks! Will accept answer in couple minutes (once I get permission to =] )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.