Re: [PHP] Add data to three tables at once from one form
"Julian Wood" [EMAIL PROTECTED] wrote: That's it. There's nothing special to do. Except if one insert fails and the others succeed, you run into a bit of sync trouble. This is what transactions are for. You might want to consider a BDB table type, which supports transactions, then you have the option to rollback the other inserts if one of them fails. Good point. I assumed that if the original poster didn't know how to accomplish 3 DB inserts within a PHP script then transactions and rollbacks were a little too advanced to get into (and the DB being used was never stated). -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Add data to three tables at once from one form
you have the idea. Just add the other sql statements and run it again. (Just multiply the script by 3) or you can use a loop to add the next sql to run eg. $sql1= "insert statement 1"; $sql2="insert statement 2"; $sql3= "insert statement 3"; for ($i=0; $i3; $i++) { $qryno = '$sql' + $i $result = mysql_db_query($dbname, $qryno); } try that or something alongs that line should work. of course you can always refer to teh help files. How do I set up the insert statement? $query = "INSERT INTO $table VALUES ('$menu_id', '$server', '$menunumber', '$menuname')"; $result = mysql_db_query($dbname, $query); form enctype="multipart/form-data" method="post" action="?php echo $PHP_SELF ?" Anyting special I have to do with the form submit? INPUT type="submit" name="submenu" value="submenu" INPUT type=reset value="Reset" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Add data to three tables at once from one form
That's it. There's nothing special to do. Except if one insert fails and the others succeed, you run into a bit of sync trouble. This is what transactions are for. You might want to consider a BDB table type, which supports transactions, then you have the option to rollback the other inserts if one of them fails. Julian on 4/18/01 6:33 PM, Steve Werby at [EMAIL PROTECTED] wrote: "Fates" [EMAIL PROTECTED] wrote: I know how to add data to one table but how do I add data to three tables from one form? I want to do this with just one form and on one web page so it doesn't post to another page. How do I set up the insert statement? $query = "INSERT INTO $table VALUES ('$menu_id', '$server', '$menunumber', '$menuname')"; $result = mysql_db_query($dbname, $query); Add two more sets of statements like those you have for the first query. That's it. There's nothing special to do. -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Add data to three tables at once from one form
Add two more sets of statements like those you have for the first query. That's it. There's nothing special to do. MySQL also lets you stack insert statements: $sql="INSERT INTO t1 ('A'); INSERT INTO t2 ('B'); INSERT INTO t3 ('C');" This would work (but if you get an error, you'll have trouble debugging it. It'll also save minutely on execution since it only needs to call mysql_query once instead of three times. I prefer to use three explicit statements and query calls. Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]