Is it possible to have two mysqli queries like so?
mysqli_query($dblink, "INSERT INTO images (project_id, user_id, image_name, date_created, link_to_file, link_to_thumbnail, given_name) VALUES ('$project_id', '$user_id', '$image_name', '$date_created', '$link_to_file', '$thumbnail', '$ImageName')");
mysqli_query($dblink, "INSERT INTO images_history (project_id, user_id, image_name, date_created, link_to_file, link_to_thumbnail, given_name, day, month, year) VALUES ('$project_id', '$user_id', '$image_name', '$date_created', '$link_to_file', '$thumbnail', '$ImageName', '$day', '$month', '$year')");
Basically I want to update two tables in my DB. Is there a better way to do this?
It is possible with mysqli_multi_query().
Example:
The key is that you must use
mysqli_multi_queryif you want to execute more than one query in a single call. For security reasons,mysqli_querywill not execute multiple queries to prevent SQL injections.Also keep in mind the behavior of
mysqli_store_result. It returnsFALSEif the query has no result set (whichINSERTqueries do not) so you must also checkmysqli_errorto see that it returns an empty string meaning theINSERTwas successful.See:
mysqli_multi_query
mysqli_more_results
mysqli_next_result
mysqli_store_result