jodarecode Posted March 18, 2009 Share Posted March 18, 2009 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. $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; 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) no errors only saves and/or updates the last field. in this case 'orderno' Keep in mind the form has over 240 fields but I minimized it to show in forum Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.