smilesmita Posted August 2, 2007 Share Posted August 2, 2007 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! Link to comment https://forums.phpfreaks.com/topic/63102-solved-db-error-error-syntax-error-at-or-near-array/ Share on other sites More sharing options...
deadimp Posted August 2, 2007 Share Posted August 2, 2007 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. Link to comment https://forums.phpfreaks.com/topic/63102-solved-db-error-error-syntax-error-at-or-near-array/#findComment-314395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.