php foreach loop insert into two tables -


I want to insert the table into the table.

Each name can have several addresses.

name will be in table1 and all addresses will be related to another table2 in name

My array is below:

  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) ");}}    

Drilling is not it should be:

  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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -