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

The "Commands out of sync; you can't run this command now" error in PHP usually occurs when you have called a MySQL function in an incorrect order.

This error occurs because MySQL has a command buffer that needs to be used in a specific order, and when you try to execute a command out of order, it results in this error.

Watch a course Learn object oriented PHP

Here are a few things you can try to fix this error:

  1. Make sure that you are calling mysql_query() only once for each SQL statement.
  2. Make sure that you are calling mysql_use_result() or mysql_store_result() for every SELECT statement before calling any other MySQL function.
  3. If you are using mysql_use_result(), make sure to call mysql_free_result() after you have finished processing the result set.

I hope this helps! Let me know if you have any questions.