Wednesday 15 July 2015

php - Multidimensional array from form submit that i need to get the data and insert it into mysql -


I have the following dump from the form on which I am working and I need to put the data in MySQL. My problem is that I am a little confused about how I can handle data from the form (how to do it or to find a better way to handle it).

Dump: array (4) ["product_name_" => Array (2) [0 = & gt; String (10) "Top Horti" 2 = & gt; String (7) "Pix Gel"] "Quantity_" => Array (2) [0 = & gt; String (1) "2" 2 = & gt; String (1) "3"] "price_" = & gt; Array (2) [0 = & gt; String (3) "200" 2 = & gt; String (2) "10"] "submit" = & gt; String (6) "Submit"]

This will help transform the array A friendly format:

  $ myData = array (); $ {$ MyData [] = array ('name' = & gt; $ item, 'quantity' => $ formData ['quantity _'] [$] $ $ key] 'value' = & gt; $ formData ['Value'] [$ key]); }   

You can loop over to $ myData to insert.

Note that it does not check that the array key is present and it assumes that there will always be quantity and value for each product name.

No comments:

Post a Comment