Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.