Jump to content

Duplicate entry '' for key 2 - please help!!


bian101

Recommended Posts

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 :D

Link to comment
https://forums.phpfreaks.com/topic/211309-duplicate-entry-for-key-2-please-help/
Share on other sites

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

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.