Jump to content

registration form Help


prezident

Recommended Posts

I'm making a registration form and i want to add a user when i click the registration button, but the user can not already be in the database, i set  the user to be unique inside of the database and when i try to add a new user it gives an error message, but instead of that error message i would like to input please enter another user-name or user already exist something like that the error message says duplicate entry 'username' inside of db basically...

can someone help me with this ?

 

[attachment deleted by admin]

Link to comment
Share on other sites

And in your // failure logic you can test the value that mysql_errno returns to see if the query failed due to a duplicate key (the value returned should be 1062, but you should test this to make sure) and setup your message and logic needed to prompt the user for a different username.

 

thank you after i made the changes above - to handle the errors myself instead of using die its being weird instead of catching the duplicated user-name its the user go through but not saving it to the database.

Link to comment
Share on other sites

The comparison operator is == not =

 

There's no need to check if $user equals $username though, you know if your query returns any results that the two must match because you used a WHERE clause in your query.

 

ps: Can you please post your code in the forum itself. Posting images will make it difficult for people to copy your code in order to help you.

Link to comment
Share on other sites

The comparison operator is == not =

 

There's no need to check if $user equals $username though, you know if your query returns any results that the two must match because you used a WHERE clause in your query.

 

ps: Can you please post your code in the forum itself. Posting images will make it difficult for people to copy your code in order to help you.

 

ok i'm going to edit it right now and resend im sorry i didn't know how to do it i guess i just copy and paste the code huh ?

Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM login WHERE user ='$user'");
$row = mysqli_num_rows($result);
//$sql = mysql_fetch_array($row);
//$usernme = $row['user'];
if ($row > 0 )
{
    echo "USERNAME ALREADY VALID PLEASE ENTER A NEW USER";
}
else
{
mysql_query("INSERT INTO login(fname, lname, user, pass, dob) VALUES ('$fname', '$lname', '$user', '$pass','$DOB')");
echo "<b> YOUR ACCOUNT HAS BEEN ADDED <br/> ";
    }
?>

 

this is the updated code it's still not working I'm thinking the problem is with the if ($row > 0) part....

 

i think i should use ($row == 0)

 

but if i do that all new users get echo "USERNAME ALREADY VALID PLEASE ENTER A NEW USER <br/>";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.