homepage Welcome to WebmasterWorld Guest from 23.21.9.44
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Running multiple INSERTS in same $sql
Probably very simple....
ukgimp




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

Hello

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

Cheers

 

The_Warden




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

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...

Ex.

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved