Jump to content

[SOLVED] DB Error: ERROR: syntax error at or near "Array


smilesmita

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.

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.