Jump to content

On Duplicate Key Update


piearcy

Recommended Posts

Not sure why this isn't working so thought I would see if others laying eyes on it will see the problem. 

mysqli_query($mysqliConn, 'INSERT INTO '.$table.' (id, description, car_initials, car_no, site_id, product_id, status_code, available_dt)
VALUES ('.$id.', '.$description.', '.$carInitials.', '.$carNo.', '.$siteId.', '.$productId.', '.$statusCode.', '.$availableDt.')
ON DUPLICATE KEY UPDATE description = '.$description.', car_initials = '.$carInitials.', car_no = '.$carNo.', site_id = '.$siteId.', product_id = '.$productId.', status_code = '.$statusCode.', available_dt = '.$availableDt.'
') or apiError( array( 'index' => $i, 'id' => $id ) );

Description is a combination of the car initials and car number and is placed in a unique key in the MySql database. But I'm getting this:

Duplicate entry 'MWCX300310' for key 'description'. 

 

I should not be getting this since I'm doing the on duplicate key update. 

 

Am I missing something here? 

 

And yes I know this is not a prepared statement. I took this project over from another developer and am in the process of changing everything over to PDO to rectify that problem. 

 

Thanks,

Dave

Link to comment
https://forums.phpfreaks.com/topic/296263-on-duplicate-key-update/
Share on other sites

What keys do you have on that table? Do a SHOW CREATE TABLE $table if you're not sure.

 

More than one key? Sounds like you're violating one key (that isn't the description), triggering the ON DUPLICATE KEY, but then violating the description key with the new value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.