bian101 Posted August 20, 2010 Share Posted August 20, 2010 Hey guys! I know, I know this problem is EVERYWHERE but i just dont understand! I have a solid knowlage of php but my SQL skills are low, so i dont know too much about Keys and stuff. But my error is: Duplicate entry '' for key 2. The thing that im working on at this section is logging in with facebook. The code that presents my error is: $sql = "SELECT * FROM users WHERE uid=".$uid; $fbid = mysql_query($sql); $num_rows = mysql_num_rows($fbid); if(mysql_num_rows($fbid) < 1) { echo "You are not logged in. "; mysql_query("INSERT INTO `users` (`uid`) VALUES ('".$uid."')") or die(mysql_error()); } else { mysql_query("UPDATE users SET logged = '1' WHERE uid=".$uid); //mysql_query("UPDATE users SET full_name = $me WHERE uid=".$uid); echo "Your Logged in "; echo $me['name']; ?> Continue to <a href="removed "> My Settings </a>. <? } Any help is welcome Quote Link to comment https://forums.phpfreaks.com/topic/211309-duplicate-entry-for-key-2-please-help/ Share on other sites More sharing options...
bian101 Posted August 20, 2010 Author Share Posted August 20, 2010 Any one know much on this topic? Quote Link to comment https://forums.phpfreaks.com/topic/211309-duplicate-entry-for-key-2-please-help/#findComment-1101818 Share on other sites More sharing options...
Pikachu2000 Posted August 21, 2010 Share Posted August 21, 2010 You're attempting to insert a duplicate value into a table field that is a unique indexed field. Just like the error says. A login script shouldn't need an INSERT query at all (in general). Quote Link to comment https://forums.phpfreaks.com/topic/211309-duplicate-entry-for-key-2-please-help/#findComment-1101971 Share on other sites More sharing options...
sasa Posted August 21, 2010 Share Posted August 21, 2010 try to change $sql = "SELECT * FROM users WHERE uid=".$uid; with $sql = "SELECT * FROM users WHERE uid='".$uid."'"; Quote Link to comment https://forums.phpfreaks.com/topic/211309-duplicate-entry-for-key-2-please-help/#findComment-1101976 Share on other sites More sharing options...
bian101 Posted August 21, 2010 Author Share Posted August 21, 2010 Hey, Somehow i dont know why without me changing that its been implemented, not a clue how i managed to change it, but still no fix. We think its something to do with a key in the database? Not a clue Quote Link to comment https://forums.phpfreaks.com/topic/211309-duplicate-entry-for-key-2-please-help/#findComment-1101998 Share on other sites More sharing options...
Zane Posted August 21, 2010 Share Posted August 21, 2010 What's the datatype for the primary key? And also, is it set to auto-increment? Quote Link to comment https://forums.phpfreaks.com/topic/211309-duplicate-entry-for-key-2-please-help/#findComment-1102000 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.