Got an error- 'Duplicate entry '9' for key 'accountID' ERROR 1062.
I'm trying to use ON DUPLICATE KEY UPDATE in order to update any fields that are already inserted into the database.
Background about program:
I have three tables. Account, address, and profile. Because of foreign key constraints on person and on address, I cannot use a simple update query, therefore I'm using this. I'm not sure if I'm using it incorrectly, or that I don't understand the logic of it. If anyone can give a hand that would be great. I believe the problem lies in the method of inserting the form data. I've added a description below.
In my function, I update two tables (address and person) in the same form. Because person refers to an addressID, address data needs to be inserted before the person data can be inserted. According to my code, the issue lies with the person data insert (w/ on duplicate ...), although the address insert (on duplicate...) works, it doesn't update a row, it just adds a new row - which is wrong still. I'm trying to understand the issue with the second insert statement below.
Note: assume that all of the array fields ($addressData, $profileData) are correct, they work without the ON DUPLICATE KEY UPDATE function.
Thanks!
$this->db->insert('address', $addressData).'ON DUPLICATE KEY UPDATE country=country+1, city=city+1, streetName=streetName+1, postcode=postcode+1, buldingNumber= buldingNumber+1';
$this->db->insert('person', $profileData).'ON DUPLICATE KEY UPDATE firstname=firstname+1, lastname=lastname+1,addressID='.$addressID.'+1, dob=dob+1, religion=religion+1, locationFlexibility=locationFlexibility+1';