Jump to content

User already exists


watsonowen

Recommended Posts

Ok i've been working on my forum recently to register members and I'm doing some error checking now and for some reason I'm unable to get it to find existing members if someone tries to register with a username already in the database. So here is the code any help would be nice.

 

$getUser = MYSQL_QUERY("Select Username FROM **** WHERE Username=\ '" .$user. "\'");

 

 

while($row = mysql_fetch_array($getUser))

{

  if (!empty($row['Username']))

  {

  echo "<center><font face='Verdana, Arial, Helvetica, sans-serif' color='#FF0000'>Username already taken! Please try again!<br />You  will be redirected in 5 seconds.</font></center>";

 

  header( 'refresh: 5; url=register.php' );

  }

  else

  {

  $addprofile = MYSQL_QUERY("INSERT INTO ***  (Profile_ID, IP_Address, Username, Password, First_Name, Last_Name, City, State, Country, Email, Gender, Date)". "VALUES ('NULL', '$ip', '$user', '$userPswd', '$first', '$last', '$city', '$state', '$country', '$email', '$gender', '$date')");

//success...

 

  echo "<h1 class='style2'>Fight Night Challenge</h1><h2 class='style2'>You have Registered with the IP Address of <font color='white'>" . $ip . "</font></h2>";

  }

}

 

I do know that the insert works I'm just having a problem with the while loop trying to find the user.

Link to comment
https://forums.phpfreaks.com/topic/106807-user-already-exists/
Share on other sites

Instead of looping, just check to see how many rows were returned. You can do this with:

 

if(mysql_num_rows($getUser) == 0) { ... }

 

Or you could have mysql do the counting for you so that you don't have to return unnecessary results:

"SELECT count(`column`) FROM `table` WHERE `user` LIKE '$value'"

 

Also you should be VERY careful with your variables. Make sure that you escape any unwanted characters with addslashes() or mysql_real_escape_string(). Otherwise someone could very easily wipe out your database or steal information from it.

Link to comment
https://forums.phpfreaks.com/topic/106807-user-already-exists/#findComment-547534
Share on other sites

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.