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
Share on other sites

I seem to remember you asked this question before.

 

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).

Link to comment
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.