Jump to content

check username


droidus

Recommended Posts

i am having issues checking the availability of a username.  here is my code:

 

<?php
$loginUsername = "admin";

mysql_select_db($database_uploader, $uploader);    
      	$query = "SELECT * FROM members WHERE uname='"
        . mysql_real_escape_string($loginUsername) . "'";

	// make sure the username and password were found
      	if (mysql_num_rows($result) > 0) {
		echo "This username is taken.  Please choose a different one.";
	} else {
		echo "This username is available.";
	}
	mysql_close($con);
?>

 

the username, admin, does exist.  but i get an output of "This username is available. ".  why?

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/243047-check-username/
Share on other sites

You are not executing your query, so your logic always reports that the username is available.

 

You should also be developing and debugging your code on a system with error_reporting set to E_ALL (or even better a -1) and display_errors set to ON so that all the php detected errors will be reported and displayed, you will save a TON of time.

Link to comment
https://forums.phpfreaks.com/topic/243047-check-username/#findComment-1248280
Share on other sites

i don't recommend inserting a function in your query like that...

 

<?php
$loginUsername = "admin";

mysql_select_db($database_uploader, $uploader);    
      	$query = sprintf("SELECT * FROM members WHERE uname='%s'", mysql_real_escape_string($loginUsername));
        mysql_query($query);

	// make sure the username and password were found
      	if (mysql_num_rows($result) > 0) {
		echo "This username is taken.  Please choose a different one.";
	} else {
		echo "This username is available.";
	}
	mysql_close($con);
?>

Link to comment
https://forums.phpfreaks.com/topic/243047-check-username/#findComment-1248281
Share on other sites

Do all your functions and processing, etc outside of your query statement, then insert it as a variable.

 

e.g.

$loginUsername = "admin";
$loginUsername=mysql_real_escape_string($loginUsername);
mysql_select_db($database_uploader, $uploader);
$query = sprintf("SELECT * FROM members WHERE uname='%s'", $loginUsername);
mysql_query($query);

Link to comment
https://forums.phpfreaks.com/topic/243047-check-username/#findComment-1248493
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.