I just want to determine if someone with this "cid" is already registered. Here is the code:

	//determines if user is already registered

$query = sprintf("SELECT cid from userinfo where cid='%s' LIMIT 1) 
				  VALUES('%s')", 
				  mysql_real_escape_string($cid, $con));
$exec = mysql_query($query, $con); //executes query
$num_rows = mysql_num_rows($exec); //determines how many rows are returned
if($num_rows == "1")
{
	die("You are already registered");

}

It gives me any error of:

Warning: sprintf() [function.sprintf]: Too few arguments in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\newatc.php on line 31

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\newatc.php on line 33

     $query = sprintf("SELECT `cid` from `userinfo` where cid='$cid'"); 

    i changed it after noticing that error. It works now i think. I think there is a problem with my if statement though. No matter weither they are in there or not it displays "you are already registered"

    EDIT: I fixed it by myself lol. I guess that means i'm making progress. yay!

      Also note that if you simply add a PRIMARY or UNIQUE index on the "cid" column, you could ditch this SELECT query and simply perform the INSERT query when you're processing the registration. If the [man]mysql_errno/man is 1062 (the "duplicate entry 'xxx' for key n" error), display the 'already taken' error message.

      shrug Just thought I'd offer a way to optimize the SQL. Anyway, glad you got the issue resolved.

        Thanks! I appreciate that. I'll definatly put that into play

          Write a Reply...