Forum Moderators: coopster

Message Too Old, No Replies

Updating a field using an array

php, mysql, html, javascript

         

jodarecode

8:41 pm on Jun 20, 2008 (gmt 0)

10+ Year Member



I cant figure out whats wrong with this script. basically I want to update a field "value" in mysql db with an array to match the "fieldid" and unique login "userid"


$fieldstoinsert=array('purchaser', 'orderno', 'contact');
$query = "UPDATE `db`.`formdata` SET `value` = '$fieldstoinsert' WHERE `formdata`.`userid` ='$saveas' AND CONVERT( `formdata`.`value` USING utf8 ) = '$fieldstoinsert' LIMIT 1";
foreach($_POST as $fieldid => $value){
if(in_array($fieldid,$fieldstoinsert)){
if(trim($value)!=""){
$query.="('$value'),";
}
}
}
$query=substr($query,0,-1);
echo $query;

//when I echo $query; I get:


UPDATE `db`.`formdata` SET `value` = 'Array' WHERE `formdata`.`userid` ='//tag that matches for user form name//' AND CONVERT( `formdata`.`value` USING utf8 ) = 'Array' LIMIT 1('answer3'),('answer3'),('answer3')

//and when I run it I get:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('answer3'),('answer3'),('answer3')' at line 1

Can anyone help me from smacking my head anymore?

coopster

9:41 pm on Jun 20, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, jodarecode.

There's all kinds of mess going on in there! :)
$fieldtoinsert is an array. That is why the word "Array" is printing in your query statement. What are you expecting the query statement to look like once your code has run and completed building the query statement?