User Registration Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Phillips126
Forum Newbie
Posts: 9
Joined: Thu Feb 18, 2010 2:21 pm

User Registration Help

Post by Phillips126 »

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). :banghead:

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 />";
    }
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
Phillips126
Forum Newbie
Posts: 9
Joined: Thu Feb 18, 2010 2:21 pm

Re: User Registration Help

Post by Phillips126 »

Just figured it out... I knew it was simple, just sometimes it's always the last thing you try.

Ended up using an if else statement preventing the form to send the data to the mysql database.
Post Reply