>Now, if i hit enter again it will say:
>"Please fill out all fields to proceed.
>Sorry, username is already taken, please choose another.
>There seems to be a problem with the database."

So this is the problem?

>Here is my code:
><form method=post action="<? echo $PHP_SELF; ?>">
><table cellpadding=2 cellspacing=0 border=0>
><td>Username:</td><td><input type="text" name="username" size=10></td><tr>
><td>Password:</td><td><input type="password" name="password"
><td>Email:</td><td><input type="text" name="email" size=15></td><tr>
><td> </td><td><input type="submit" name="submit" value="register"></td>
>if(isset($submit)) {
>// Make sure all fields are filled out
>if ($username=="" or $password=="" or $email=="") {
>echo("Please fill out all fields to proceed.<br>");


You need to add an "exit;" to tell PHP to terminate the if-loop.
If oyu don't do so the rest of the script is executed and thus
the empty usrname and password are entered. That's why you
get "usrname already taken" after the second submit.

>// Make sure there is not the same name in the database
>$query = "SELECT COUNT(*) FROM user WHERE name = '$username'";
>$result = mysql_query($query);
>if (!$result) {
>echo("There seems to be a problem with the database.<br>");
>if (mysql_result($result,0,0)>0) {
>echo("Sorry, username is already taken, please choose another.<br>");


here again. but if your username is unique entering it to the DB won't
work anyway and you could leave it, but I think it is cleaner to put
it there.

You could also put the whole processing into a seperate script and then use
header(...)s to redirect back to the loginscreen.

hope it helps

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to