the code below saves but only the last field. When I update that field it updates just fine, but its confined to only that field to insert or update.
so, its working but for only one field and not both.
[code=php]$fieldstoinsert=array(‘purchaser’, ‘orderno’);
$query = “INSERT INTO formdata (userid, fieldid, value, saveas) VALUES”;
foreach($_POST as $fieldid => $value){
if(in_array($fieldid,$fieldstoinsert)){
if(trim($value)!=””){
$query.= “(‘$userid’, ‘$fieldid’, ‘$value’, ‘$saveas’),”;
}
}
}
$query=substr($query,0,-1);
//Primary key is userid
$query .= ” ON DUPLICATE KEY UPDATE fieldid=VALUES(fieldid), value=VALUES(value), saveas=VALUES(saveas)”;
echo $query;
[code=php]INSERT INTO formdata (userid, fieldid, value, saveas) VALUES(’27’, ‘purchaser’, ‘me’, ‘test1′),(’27’, ‘orderno’, ‘1234’, ‘test1’) ON DUPLICATE KEY UPDATE fieldid=VALUES(fieldid), value=VALUES(value), saveas=VALUES(saveas)
Structure from old post: [URL=”http://www.webdeveloper.com/forum/showthread.php?t=183148″]http://www.webdeveloper.com/forum/showthread.php?t=183148