Jump to content


Photo

Extremely Basic Login/Update Script


  • Please log in to reply
6 replies to this topic

#1 dturnbull

dturnbull
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 13 May 2006 - 04:14 AM

I have a really simple database/script.
Users sign up with an email, username, and password (and some other fields), and then a new page is created for them with their details.

Could someone give me some help on how to make it so users can use their email/password to login then update their details?

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 May 2006 - 05:15 AM

[!--quoteo(post=373416:date=May 13 2006, 02:14 PM:name=David Turnbull)--][div class=\'quotetop\']QUOTE(David Turnbull @ May 13 2006, 02:14 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I have a really simple database/script.
Users sign up with an email, username, and password (and some other fields), and then a new page is created for them with their details.

Could someone give me some help on how to make it so users can use their email/password to login then update their details?
[/quote]


I can not write the entire code for you, but here is the designing:

1. Set up your database, make sure all the field names and field datatypes are good in place.
2. Write a Register.php file. This page contain a registration form for new user to register. Registration will be consistent with the fields in your database table.
3. Write a Login.php file. This file contain a login form (username and password). when click submit, it will check against database. If verified, redirect to the profile.php, otherwise, stay on the same login with a message.
4. the profile.php, This file contain a very similar form as registration, but instead with a update button at the bottom. profile.php first read the data for this user from db, then parse them to the form.


Life's too short for arguing.

#3 dturnbull

dturnbull
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 13 May 2006 - 05:41 AM

How would I check the username/password against the database? that is wat I am having troubles with.

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 13 May 2006 - 06:43 AM

[!--quoteo(post=373427:date=May 13 2006, 03:41 PM:name=David Turnbull)--][div class=\'quotetop\']QUOTE(David Turnbull @ May 13 2006, 03:41 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How would I check the username/password against the database? that is wat I am having troubles with.
[/quote]

this is where sql come in.

One most common way to do this, is to query the database, check to see if there exist a record with that given username and given password.

if there is, then the username and password match, since username is unique, there is only 1 record that able to match a given username and password.

sample query:

$rs = mysql_query("select count(*) as count from tablename where username='$username' and password='$password'");

if (mysql_num_rows($rs) == 1)
{
echo 'password and username is correct';
}
else
{
echo 'password username did not match';
}

tablename is the table in db that contain user registration information.
$username, $password are retrieve from login form.
Life's too short for arguing.

#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 13 May 2006 - 07:19 AM

There are TONS of simple membership tutorials on the net. Take one.

#6 dturnbull

dturnbull
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 13 May 2006 - 07:35 AM

thnx for the help. worked great.

#7 Flukey

Flukey
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 13 May 2006 - 11:19 PM

Store the password as an MD5 hash.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users