Jump to content

Help with pulling usernames from database


herghost

Recommended Posts

Hi all, I am working on a signup for which checks the database for a username and displays a message using ajax if the name is available or not.

 

 

I have the username dave in the database, yet when I type dave into the box it still shows as available?

<?php
include('connect.php');
$query = "SELECT * FROM user_signup where username = '{$_POST['username']}'";

$result = mysql_query($query);
if(mysql_num_rows($result)>0){
//username already exists
echo "yes";
}else{
echo "no";
}



?>

 

What do you mean "shows it as available"? If you mean when you type a username in that is already in the database, it echos back "yes", then it's doing exactly what it's written to do.

 

Additionally, a SELECT COUNT(`primary_key_field`) query rather than mysql_num_rows() on a wildcard SELECT *, would be much more efficient in that application.

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.