JazzyB Posted October 16, 2006 Share Posted October 16, 2006 Hi,I am trying to send multiple data via one form. I have 4 tables each in the same form. Here is an example:[code]<form name="form1" id="form1" method="post" action="process.php"> <table width="428" border="0" cellspacing="6" cellpadding="0"> <tr> <td>Field 1: </td> <td><input type="text" name="field1" /></td> </tr> <tr> <td>Field 2:</td> <td><input type="text" name="field2" /></td> </tr> <tr> <td>Field 3:</td> <td><input type="text" name="field3" /></td> </tr> <tr> <td>Field 4:</td> <td><input type="text" name="field4" /></td> </tr> </table> <br /> <table width="428" border="0" cellspacing="6" cellpadding="0"> <tr> <td>Field 1: </td> <td><input type="text" name="field1" /></td> </tr> <tr> <td>Field 2:</td> <td><input type="text" name="field2" /></td> </tr> <tr> <td>Field 3:</td> <td><input type="text" name="field3" /></td> </tr> <tr> <td>Field 4:</td> <td><input type="text" name="field4" /></td> </tr> </table> <br /> <table width="428" border="0" cellspacing="6" cellpadding="0"> <tr> <td>Field 1: </td> <td><input type="text" name="field1" /></td> </tr> <tr> <td>Field 2:</td> <td><input type="text" name="field2" /></td> </tr> <tr> <td>Field 3:</td> <td><input type="text" name="field3" /></td> </tr> <tr> <td>Field 4:</td> <td><input type="text" name="field4" /></td> </tr> </table> <br /> <table width="428" border="0" cellspacing="6" cellpadding="0"> <tr> <td>Field 1: </td> <td><input type="text" name="field1" /></td> </tr> <tr> <td>Field 2:</td> <td><input type="text" name="field2" /></td> </tr> <tr> <td>Field 3:</td> <td><input type="text" name="field3" /></td> </tr> <tr> <td>Field 4:</td> <td><input type="text" name="field4" /></td> </tr> </table> <p> <input type="submit" name="Submit" value="Submit" /> </p></form>[/code]Is it possible to send all this data to a mysql database, so that 4 rows are inserted in one go? If so please could you provide me with any info that would help. It would help a lot if anyone can provide an example. Many thanks in advanceJaz Quote Link to comment https://forums.phpfreaks.com/topic/24107-sending-multiple-data-to-mysql-db/ Share on other sites More sharing options...
.josh Posted October 16, 2006 Share Posted October 16, 2006 insert into table (column1, column2, column3) values ( 'value1','value2','value3') , ('value1','value2','value3'), etc.. "; Quote Link to comment https://forums.phpfreaks.com/topic/24107-sending-multiple-data-to-mysql-db/#findComment-109580 Share on other sites More sharing options...
Barand Posted October 16, 2006 Share Posted October 16, 2006 field1 in the last section will override field1 in the previous sections etc so you only get the last set of values.Rename the input fields as field1[], field2[] etc in all 4 sections then [code]<?phpfor ($i = 0; $i < 4; $i++) { $f1 = get_magic_quotes_gpc() ? $_POST['field1'][$i] : addslashes($_POST['field1'][$i]); $f2 = get_magic_quotes_gpc() ? $_POST['field2'][$i] : addslashes($_POST['field2'][$i]); $f3 = get_magic_quotes_gpc() ? $_POST['field3'][$3] : addslashes($_POST['field3'][$i]); $f4 = get_magic_quotes_gpc() ? $_POST['field4'][$i] : addslashes($_POST['field4'][$i]); mysql_query("INSERT INTO tablename (col1, col2, col3, col4) VALUES ('$f1', '$f2', '$f3', '$f4')");}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24107-sending-multiple-data-to-mysql-db/#findComment-109711 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.