Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

mysql sporadic unexpected "Duplicate entry"

11:23 pm on Aug 1, 2012 (gmt 0)

5+ Year Member

I have this code:

$query = "SELECT * FROM pRecord WHERE recordID='{$catalogKey}'";
$resultSet = mysql_query($query);
if(!$resultSet) {
die("Database query failed: " . mysql_error());

if(mysql_num_rows($resultSet) === 0) {
$command = "INSERT INTO pRecord ( recordID, knownPhotoInstance, fileSize, duplicateOf )
VALUES ( '{$catalogKey}', '{$picString}', '{$fileSize}', '{$duplicateOf}' )";

$result = mysql_query($command);
if(!$result) {
die("Database query failed: " . mysql_error());

Occasionally, when I run this script, it will report "Duplicate entry", although I'm checking for that ahead of time as you can see. If I run the script again I don't get the error and everything is fine, usually. Anyone have any thoughts on why I'd occasionally get this strange surprise that would go away upon running the script again?
9:10 pm on Jan 20, 2013 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

It's odd that would happen UNLESS your lookup key ($catalogKey) in the first query was changed. Can you check that on your error dump as well? That may help get you started (in the event you are still having this issue as I realize this is from August!)