Registration

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
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Registration

Post by TheCase »

Hi I am putting this code in my registration file

Code: Select all

$query = "SELECT id FROM login WHERE username='$username'"; 
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); 

if (mysql_num_rows($result) == 0) { 

} else { 
echo '<p><font color="red" size="+1">That username has allready been registered.</font></p>'; 
}
but it says That username has allready been registered but then it registers you. If I include exit(); they have to hit back to see the page again and I don't wan't that so how do i like make the script stop from there and not register the person, thanks
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

I think your problem can be in when you posted pege.Because I saw ur code, I haven't found error there
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Post by TheCase »

My orginal code in other posts are old. I have redone the regstration page. If thats what you are talking about.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

Where is your actual registration code for them to register you?

If its after the above code, of course it would still register you unless you:

1. Replaced the registration code within the if statement so that only if the username isn't taken, it would continue on with the registration or
2. Set an bool $error whenever an error occurs and check whether the bool is true or false before it continues on to register.

Of course there are other alternatives too, but those are the basic ones.
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Post by TheCase »

That's just a bit of the code the whole thing is

Code Removed.
Last edited by TheCase on Sat Jan 06, 2007 8:52 am, edited 1 time in total.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

Before registering, your script checks whether any of the checks have failed, except the username taken validation..

Try changing the if/else statement in the block of code you first posted to:

Code: Select all

if (mysql_num_rows($result) == 0) {
$username_available = true;
} else {
$username_available = false;
echo '<p><font color="red" size="+1">That username has allready been registered.</font></p>';
}
and also modifying your check to see whether the username is available or not before registering

Code: Select all

if ($username && $email && $password && $rank && $division && $username_available) {
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Post by TheCase »

Yup. That worked I got the error message username allready taken then i get the error

You could not be registered due to a system error. We apologize for any inconvenience.

why do I get both here is the code again

code removed by author

Thanks for your help
Last edited by TheCase on Sat Jan 06, 2007 11:41 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The code is commented to tell you why, but ...
TheCase wrote:

Code: Select all

if (mysql_num_rows($result) == 0) {
$username_available = true;
} else {
$username_available = false;
echo '<p><font color="red" size="+1">That username has allready been registered.</font></p>';
}

:snip:

        if ($username && $email && $password && $rank && $division && $username_available) {
:snip:
                        } else { // If it did not run OK.
                                echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>';
                        }
TheCase
Forum Newbie
Posts: 8
Joined: Fri Jan 05, 2007 1:19 am

Post by TheCase »

I know, but the reason why it did not run ok is because the username is allready taken. I don't wan't that message there because there is allready a message saying the username is taken. I put it there incase of SQL error.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

TheCase wrote:I put it there incase of SQL error.
The code I quoted would suggest otherwise.
Post Reply