|
-
Dec 4th, 2009, 01:29 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] user registration?
i'm trying to write my website from beginning again because i want to learn programming websites so i decided to delete my old website and start with opening notepad well now i come to user registration, i realize that if i just write to the database then it will add the user even if there already is a user with that name... so i come here to ask how i can check if the username is already taken...
-
Dec 4th, 2009, 01:59 PM
#2
Addicted Member
Re: user registration?
Hi,
I still don't get it how this problem relates to your use of Notepad.
well now i come to user registration, i realize that if i just write to the database then it will add the user even if there already is a user with that name... so i come here to ask how i can check if the username is already taken...
Is this the problem at hand?
-
Dec 4th, 2009, 02:31 PM
#3
Thread Starter
Fanatic Member
Re: user registration?
what i mean is that i make everything from beginning the problem is i need to check if the data is already stored (username) in the database..
edit: i think what you don't get is that i post from a php form into the database...
Last edited by Justa Lol; Dec 4th, 2009 at 02:36 PM.
-
Dec 4th, 2009, 04:50 PM
#4
Re: user registration?
your terminology is a little off -- you are not posting into a database. a form in your PHP script is POSTing (the request method) to another PHP script (or perhaps the same script sending the request), which is in turn interacting with your database.
either way, what you need to do is query the database for any users that exist in your database with the username that is currently trying to register. a small example:
PHP Code:
<?php
//has the form been submitted?
if($_SERVER['REQUEST_METHOD'] == "POST"){
//yes!
//sanitise the username
$username = mysql_real_escape_string($_POST['username']);
//query the database
$sql = "SELECT uid FROM [b]user_table[/b] WHERE username='$username'";
$query = mysql_query($sql);
//if any results returned, this username is in use
if(mysql_num_rows($query) == 0){
//continue with adding the user
//...
}else{
//show some sort of error or something
}
}
?>
ask questions if this doesn't make sense to you.
-
Dec 5th, 2009, 06:37 AM
#5
Thread Starter
Fanatic Member
Re: user registration?
i take this back, i forgot to change uid to id..
thanks kows i got it working
Last edited by Justa Lol; Dec 5th, 2009 at 06:42 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|