Welcome to WebmasterWorld Guest from 184.108.40.206 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
Running multiple INSERTS in same $sql Probably very simple.... ukgimp
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 ); mysql_close($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
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....";