This question already has an answer here:
These two PHP MySQL queries work.
mysql_query("DELETE FROM videos WHERE id='10';");
mysql_query("DELETE FROM comments WHERE videoId='10';");
This single query fails due to a MySQL syntax error pertinent to the latter DELETE operation.
mysql_query("DELETE FROM videos WHERE id='10';DELETE FROM comments WHERE videoId='10';");
I've stared hard and can't see the syntax error. What is it?
</div>
You cannot execute multiple queries with mysql_query
. If you really want to (security risk!), use mysql_multi_query
. (And you should use the newer mysqli_*
functions). It's a good idea two embed those two calls in a transaction.
But this looks a lot like you really want to define foreign key constraints. I highly recommend them, if you are already using InnoDB.
Not supported by mysql_query see How can I put two queries in one mysql_query? use http://docs.php.net/mysqli.multi-query
Multiples queries are not supported in this function.