Jump to content

[SOLVED] Insert Array Into Database


forumnz

Recommended Posts

I'm having big problems trying to insert an array into a database. Here is what I have so far:

 

<?php
$e = '[{"qty":66,"price":5,"item":"ggg","des":"g","acc":"h","tax":"h"},{"qty":66,"price":5,"item":"ggg","des":"g","acc":"h","tax":"h"}]';
$d = json_decode($e, true);

function mysql_insert_array($d) {
foreach ($d as $field=>$value) {
	$fields[] = '`' . $field . '`';

		$values[] = "'" . mysql_real_escape_string($value) . "'";

}
$field_list = join(',', $fields);
$value_list = join(', ', $values);

mysql_query("INSERT INTO acc_rec_inv (" . $field_list . ") VALUES (" . $value_list . ")")or die(mysql_error());


}
?>

 

What could be the problem?

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/157415-solved-insert-array-into-database/
Share on other sites

Ken: How can you tell that, if you don't know how this function is being used? (Which is a question I asked in previous topic, but got no answer).

Because I know what the OP is trying to do from his previous 4 topics on this matter. :D Failing at that though.

 

forumnz, you have to call the function in that file via mysql_insert_array($d);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.