homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

mysql sporadic unexpected "Duplicate entry"

5+ Year Member

Msg#: 4481108 posted 11:23 pm on Aug 1, 2012 (gmt 0)

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?



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

Msg#: 4481108 posted 9:10 pm on Jan 20, 2013 (gmt 0)

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!)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved