I have a series of radio objects that are inserted into a database in an array. This works great for the first time.
$query="INSERT INTO `notes_value` ( `style_color`, `note_id`, `value`, `created_at` ) VALUES ";
foreach ($params AS $key => $value) {
if (( $key != "form_key" ) && ( $key != "stylecolor" ) && ( $key != "key" )){
$values[] = "('$sku', '$key', '$value', NOW()) ";
}
}
$query .= implode(', ', $values) . ';';
I am trying to update these columns when the switch state changes by changing this:
$values[] = "('$sku', '$key', '$value', NOW()) ON DUPLICATE KEY UPDATE value = '$value'";
It will work and be updated if there is only one radio button in the array selected with this request:
INSERT INTO `notes_value` ( `style_color`, `note_id`, `value`, `created_at` )
VALUES ('1893240720', '1', 'no', NOW())
ON DUPLICATE KEY UPDATE value = 'yes';
however, when selecting several buttons, it aborts the request:
INSERT INTO `notes_value` ( `style_color`, `note_id`, `value`, `created_at` )
VALUES ('1893300667', '1', 'yes', NOW())
ON DUPLICATE KEY UPDATE value = 'no',
('1893300667', '2', 'yes', NOW())
ON DUPLICATE KEY UPDATE value = 'maybe';
Do I need to have a separate one INSERTor how to check for duplicates, and then update each one of valueits own note_id? Is this just a case of bad syntax?
change
, , . , ON DUPLICATE , .