How to verify that data has been inserted successfully?

I have two insert statements. The second will be executed only after the successful completion of the first. I would like to do the following:

$sqlone="Insert into ....."; $sqltwo="Insert into....."; If (mysql_query($sqlone)) { If (mysql_query($sqltwo)) { Show message Data inserted in both tables. } } 
+4
source share
5 answers

try it

 $query1 = '...'; $query2 = '...'; $query3 = '...'; if(mysql_query($query1)) { if(mysql_query($query2)) { if(mysql_query($query3)) { echo "success"; } else { echo "error"; } } else { echo "error"; } } else { echo "error"; } 
+6
source

It looks like you are looking for a transaction.

A little googling gave me some info on database transactions in PHP - hope this helps.

+3
source

This syntax looks as if it works like ...

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

http://au2.php.net/mysql_query

+1
source

From the documentation :

For other types of SQL, INSERT, UPDATE, DELETE, DROP, etc. statements mysql_query () returns TRUE on success or FALSE on error.

So, as far as I can see, there is no problem with what you already have.

+1
source

You can also create a database transaction in which committing one insert will execute the second insert statement.

0
source

Source: https://habr.com/ru/post/1310104/


All Articles