PDA

View Full Version : Insert array values into MySQL


rf9
07-17-2008, 11:05 AM
Hi, not sure if this should be in php or mysql forum but here it goes...

I have the following json data, that has been passed to a php file as a string via Ajax:
{"form_label": "First name", "form_type": "textfield", "form_validate": "no"},
{"form_label": "Last name", "form_type": "textfield", "form_validate": "no"} ];

I have then used json_decode which converts the string into an associative array.

I now want to insert this array data into mySQL, the data above would ideally create 2 rows in a table. Can anyone point me in the right direction, I know how to insert basic stuff to mySQL but this seems a bit trickier.

I have come across a few examples using mysql_insert_array function, anyone heard of this? it's not documented on php.net.

Any advice much appreciated.
Thanks

oesxyl
07-17-2008, 12:23 PM
I have come across a few examples using mysql_insert_array function, anyone heard of this? it's not documented on php.net.

Any advice much appreciated.
Thanks
that's because is a custom function:

http://bugs.php.net/bug.php?id=24132&edit=2

I suggest you to avoid it and build your own.

sorry, I read again next sentence, seems pretty useless, it's obvious I guess
first you must build a php array from your string and then build a mysql query to insert data into table.

from mysql point of view must be something as:

insert into tablename (form_label, form_type) values
(label1, type1), (label2, type2), ...


except this part I think that the rest of this thread must be in the php forum.

regards

rf9
07-17-2008, 01:47 PM
Thanks for all the info.