Jump to content

Recommended Posts

hi there:

 

i am getting this error :

DB Error: ERROR: syntax error at or near "Array" On query: INSERT INTO am_ups_xml ( Array ) VALUES ( );

 

I am trying to insert the array values Key=>value kind of array ...this is the snippet of the code of insert:

 

 

 

$insert_fields[] = $fields;

$insert_values[] = $value;

 

}

 

$query ="INSERT INTO am_ups_xml ( ".join(",", $insert_fields)." ) VALUES ( ".join(",",$insert_values). " );";

$r = $db->Query($query);

 

 

Please help!

I think you're looking for the implode() function.

I'm gonna take a look at what join() does.

 

EDIT: Nevermind, it's an alias. See what query is being sent to MySQL.

If you're looking into use a key/value relationship for your values, try something like this:

$stuff=array(
"name"=>"Timothy",
"age"=>22,
"worth"=>null );
$q="insert into am_ups_xml (";
$val=""; //String to hold values
foreach ($stuff as $key => $value) {
$q.="`$key`,";
$val.="'".encode($value)."',"; //encode() isn't a function - put yours here
}
//Lazy way of getting that last comma off
$q=substr($q,strlen($q)-1); $val=substr($val,strlen($val)-1); //There's probably a shorter way somewhere
$q.=") values ($val)";
...

Another way would be to use an array function, split the keys from the values, and loop from there. Whichever way fits you the best.

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.