-2

I'm getting an HTTP error 500, produced by the code below:

else if ($_POST['submit'] == "button2") {
    $tbVraag = $_POST['tbVraag'];
    $tbText = $_POST['tbText'];
    $tbQuestId = $_POST['tbQuestId'];


    $UpdateQuest = "UPDATE Vragen SET Title=:Title, `Text`=:txt WHERE QuestionId=:QuestionId";
    $stmt = $dbQuiz->prepare($UpdateQuest);

    $stmt->bindparam(':Title', $tbVraag);
    $stmt->bindparam(':txt', $tbText);
    $stmt->bindparam(':QuestionId', $tbQuestId);
    $stmt->execute();

    $tbAnt1 = $_POST['tbAnt1'];

    $UpdateAnt = "UPDATE Antwoorden SET `Text`=:antTxt WHERE AnswerId= ?";
    $statement = $dbQuiz->prepare($UpdateAnt);

    $statement->bindparam(':antTxt,', $tbAnt1);
    $statement->execute();

    echo "Update successfully completed!";

}

I have the suspicion that the error is caused by the second question in the code. Here is the error message I'm getting:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters' in /home/lab/domains/u-approachlab.nl/public_html/blendi/Website/opslaan.php:81 Stack trace: #0 /home/lab/domains/u-approachlab.nl/public_html/blendi/Website/opslaan.php(81): PDOStatement->execute() #1 {main} thrown

Ivar
  • 4,655
  • 12
  • 45
  • 50
Wanthelp
  • 23
  • 5
  • Do you get any error message? – Ivar Dec 11 '15 at 08:17
  • Yes only a 500 error nothing more :( – Wanthelp Dec 11 '15 at 08:18
  • 2
    Take a look at [this question](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display). That way you can get some error messages which can tell you more about the error. – Ivar Dec 11 '15 at 08:19
  • you are binding your params differently – roullie Dec 11 '15 at 08:21
  • see this on how to bind params using POD http://php.net/manual/en/pdostatement.bindparam.php – roullie Dec 11 '15 at 08:21
  • Oke i got this error right know: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters' in /home/lab/domains/u-approachlab.nl/public_html/blendi/Website/opslaan.php:81 Stack trace: #0 /home/lab/domains/u-approachlab.nl/public_html/blendi/Website/opslaan.php(81): PDOStatement->execute() #1 {main} thrown – Wanthelp Dec 11 '15 at 08:23

1 Answers1

1

The problem is your question mark in the second query:

$UpdateAnt = "UPDATE Antwoorden SET `Text`=:antTxt WHERE AnswerId= ?";
$statement = $dbQuiz->prepare($UpdateAnt);

$statement->bindparam(':antTxt,', $tbAnt1);
$statement->execute();

You add a question mark, but you never bind it as a parameter.

You should use something like this:

$UpdateAnt = "UPDATE Antwoorden SET `Text`=:antTxt WHERE AnswerId= :answerId";

And then also add it as a parameter:

$statement->bindparam(':answerId,', $answerId);

I don't see any answerId in your code though, so you need to get that somehow.

Ivar
  • 4,655
  • 12
  • 45
  • 50