User Registration Help
Posted: Thu Feb 18, 2010 2:32 pm
Hey all,
Im fairly new to PHP, but learning quickly.
Currently, I am working on a website that allows users to register (create username / password for extended website features).
I have a problem (which is very lame).
My registration form seems to work wonderfully... Each field gets stored in the mySQL database perfectly, however, I am having an issue with preventing the addition of an already existing Username.
I have the PHP code below, which queries the database, and finds the username. If it exists, it creates an error. (This all works good).
However, even though there is an error, the data is still sent into the database (so there is more than one person with the same username).
I know the reason why it is still sending the data is because there is no exit(); function, but when I insert that, it just takes me to a white screen (which I dont want it to do, I just want it to display the error and allow the user to try another name).
I've searched around for a solution with no luck.
Can anyone share with me a trick to prevent the data from going out, without exiting the page.
Thanks,
Phillips126
Im fairly new to PHP, but learning quickly.
Currently, I am working on a website that allows users to register (create username / password for extended website features).
I have a problem (which is very lame).
My registration form seems to work wonderfully... Each field gets stored in the mySQL database perfectly, however, I am having an issue with preventing the addition of an already existing Username.
I have the PHP code below, which queries the database, and finds the username. If it exists, it creates an error. (This all works good).
Code: Select all
// check username availability
$check_name = mysql_query("SELECT * FROM members WHERE username='$Username'");
$name_count = mysql_num_rows($check_name);
if ($name_count > 0) {
$error = "<div id=\"register_error\">Username Taken. Please Try Another.</div><br />";
}I know the reason why it is still sending the data is because there is no exit(); function, but when I insert that, it just takes me to a white screen (which I dont want it to do, I just want it to display the error and allow the user to try another name).
I've searched around for a solution with no luck.
Can anyone share with me a trick to prevent the data from going out, without exiting the page.
Thanks,
Phillips126