I need to be able to run all of the following within one query call using mysqli->multi_query, which is why this is tricky. I have a table that consists of the following columns:
- id
- event_promo_code
- event_id
When the script is run, I need to be able to insert new rows or UPDATE a row if both the id
AND event_id
match an existing record (not just one key or the other).
What I have now is:
INSERT INTO `rsvps`
SET id='$rsvpID', email='$rsvpEmail',
event_promo_code='$rsvpEventCode', event_id='$eventID'
ON DUPLICATE KEY UPDATE id='$rsvpID',
email='$rsvpEmail', event_promo_code='$rsvpEventCode', event_id='$eventID';
id
is my primary key. If I also set event_id
as a key, it does an update when either id matches a record or event matches a record, but doesn't check to see if BOTH match at the same time before it updates.