piearcy Posted May 12, 2015 Share Posted May 12, 2015 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 Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted May 12, 2015 Solution Share Posted May 12, 2015 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. Quote Link to comment Share on other sites More sharing options...
piearcy Posted May 12, 2015 Author Share Posted May 12, 2015 id is the primary key and description is a unique key. I had already looked at those. You have a point and I agree that's what's happening. Now I have to look at this further to figure out why he made description unique. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.