php foreach loop insert into two tables -
I want to insert the table into the table.
Each name can have several addresses.
My array is below: Drilling is not it should be: name will be
in table1 and all addresses will be related to another
table2 in
name
array ([name] => array ([0] = & gt; Jack [1] => Jill [ 2] = array ([0] = & gt; array ([0] = & gt; Jack_Address1 [1] => Jack_Address2 [2] => Jack_Edress 3) [1] => array ([0] = & gt; jill_address1 [1] = & gt; jill_address2 [2] => jill_address3) [2] = & gt; array ([0] => tom_address1 [1] = & gt; tom_address2 [2] => Below is the one that I tried:
foreach ($ _ request ['room_name'] as the $ key => $ value) {mysql_query ("table1 (not ) Enter values in the values ($ value) "$ insert_id = mysql_insert_id (); foreach ($ _ request ['address'] $ key1 = & gt; $ value1) {mysql_query (" Insert ID, Address in Table 2 ") value $ insert_id, $ value1) ");}}
foreach ($ _ request ['name'] $ key = & gt; $ value) {$ value = mysql_real_escape_string ($ value); Mysql_query ("Enter in Table 1 (Name) values ('$ value')"); Foreign Currency ($ _ request ['address'] [$ key] $ key1 => $ value1) {$ value1 = mysql_real_escape_string ($ value1); Mysql_query ("Enter in Table 2 (id, address) values (LAST_INSERT_ID (), '$ value1');); }}
Comments
Post a Comment