1

I tried to upload my image using PHP, but I am currently faced with an error.

It shows:

ErrorCommands out of sync; you can't run this command now.

Here's the code:

$sql1 = "INSERT INTO toothresults (class, score, classifierID, classifierName, customClass, imageSource, image, username, dateposted) VALUES ('$class1', '$score1', '$classifierID1', '$classifierName1', '$customClass1', '$imageSource1', '$img', '$username1', '$datetime1');";
$sql1 .= "INSERT INTO toothfillingsresults (class, score, classifierID, classifierName, customClass, imageSource, image, username, dateposted) VALUES ('$class2', '$score2', '$classifierID2', '$classifierName2', '$customClass2', '$imageSource2', '$img', '$username2', '$datetime2');";
$sql1 .= "INSERT INTO gumresults (class, score, classifierID, classifierName, customClass, imageSource, image, username, dateposted) VALUES ('$class3', '$score3', '$classifierID3', '$classifierName3', '$customClass3', '$imageSource3', '$img', '$username3', '$datetime3')";

//if (!mysqli_query($connection, $sql1)){
if (!mysqli_multi_query($connection, $sql1)){
    die('Error' . mysqli_error($connection));
}
//die;
mysqli_close($connection);
Isaac Bennetch
  • 10,266
  • 2
  • 27
  • 38
ohhhkeo
  • 21
  • 2
  • I believe you will find this post helpful: https://stackoverflow.com/questions/14715889/strict-standards-mysqli-next-result-error-with-mysqli-multi-query/22469722#22469722 Keep in mind, if you are INSERTing user input, then you should use prepared statements with placeholders and there is no shame in running your three queries separately in a loop. – mickmackusa Nov 06 '17 at 03:25

1 Answers1

0

If you can't use mysqli_multi_query() then it is fair for me to assume that you have previously called one or more queries previously in the script.

If you have called a single query use:

$mysqli->next_result();  // this will flush the one result

If you have called multiple queries via mysqli_multi_query()` use:

while ($mysqli->next_result()) {;}  // this will flush all of the results

Once the previous results are flushed out, you can call new single/multiple queries

For more reading, go here: Speed/best practice flushing mysqli_multi_query()

mickmackusa
  • 33,121
  • 11
  • 58
  • 86