How can I check data has been inserted successfully?
I have two insert statements. The second one will be executed only after successful execut开发者_如何学编程ion 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.
}
}
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"; }
Sounds like you're looking for transactions.
A bit of googling gave me some info on database transactions in PHP - hope it helps.
That syntax looks like it works, as...
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
From the documentation:
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, 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.
You can also create the DB transaction as well in which commit of one insert will execute the second insert statement..
精彩评论