Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Running multiple INSERTS in same $sql

Probably very simple....



10:07 am on Sep 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


In an attempt to streamline some code (php) I would like to run multple insert commands. I have no problem getting the code to work if I call two separate SQL scripts eg.

$sql1 = "INSERT INTO tableX.....";
$pResult=mysql_query( $sql1 , $db_connection );
$sql2 = "INSERT INTO tableY.....";
$pResult=mysql_query( $sql2 , $db_connection );

But when I try the following method it falls down. I get a parse error. Is there some reason why the following would not work.

$sql = "INSERT INTO tableX....;
INSERT INTO tableY....";
$pResult=mysql_query( $sql , $db_connection ); etc ect



2:05 pm on Sep 13, 2002 (gmt 0)

10+ Year Member

I believe the thing causing the problem is the semicolon (;) within $sql. PHP takes the semicolon as the closing statement. So to solve the problem I believe all you have to do is escape the semicolon (;). See below...


$sql = "INSERT INTO tableX....\;
INSERT INTO tableY....";


Featured Threads

Hot Threads This Week

Hot Threads This Month