PHP/MySql - Inserting Multiple Records

Reply

Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

PHP/MySql - Inserting Multiple Records

 
0
  #1
Mar 20th, 2008
I want to insert records into multiple tables at one go, I am doing this in the following way, is this the correct way of doing? If not, what is the better way?



  1. mysql_query("insert into table1 values('abc')");
  2. mysql_query("insert into table2 values('ttt')");
  3. mysql_query("insert into table3 values('5t6')");
  4. mysql_query("insert into table4 values('ghy')");
  5. mysql_query("insert into table5 values('gfd')");



Please help


Thanx
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: PHP/MySql - Inserting Multiple Records

 
0
  #2
Mar 20th, 2008
Yep. This is correct. But, its a good practice to have column name in your insert query. And also, Dont execute your query directly. Store the query in a variable and then execute it. This way, if you encounter any problem, you can easily print the query for manual testing.
ie.,
  1. $query = "insert into table1 (col1) values ('ttt')";
  2. mysql_query($query);
Cheers,
Naveen
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC