I have the following database MySQL table.
- id (PK, AI)
- country
- lastlogin
I have a regular query in PHP that inserts this into the table. however, logically, if this code runs several times, the same row will be inserted to the database every time.
I want my reference for checking and duplication to be the email
field, and if the email is the same, update the country
and the lastlogin
.
I checked on other questions for a similar issue and the suggested way was to use ON DUPLICATE KEY
like this
INSERT INTO <table> (field1, field2, field3, ...)
VALUES ('value1', 'value2','value3', ...)
ON DUPLICATE KEY UPDATE
field1='value1', field2='value2', field3='value3', ...
However, my primary key is not the email
field rather the id
but I don't want to run the check on it.