Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check data has been inserted successfully?

Tags:

php

mysql

I have two insert statements. The second one will be executed only after successful execution of first one. What I would like to do is:

$sqlone="Insert into .....";
$sqltwo="Insert into.....";

If (mysql_query($sqlone))
{
   If (mysql_query($sqltwo))
   {
      Show message Data inserted in both tables.
   }
}
like image 899
nectar Avatar asked Dec 22 '22 03:12

nectar


2 Answers

Try this

$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"; }
like image 174
Starx Avatar answered Jan 09 '23 16:01

Starx


Sounds like you're looking for transactions.

A bit of googling gave me some info on database transactions in PHP - hope it helps.

like image 41
Jeriko Avatar answered Jan 09 '23 16:01

Jeriko