Login Script

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
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Login Script

Post by ericburnard »

hi there i am looking for just a login script to connect to a database, and send the user to a seperate user page. I have looked around on the internet and all the examples i seem to find never work for some random reason or another.

i have a registration script and datbase set up (all details below).

I would love a script or some help in making a sript asap as its driving me loopy.

thanks

Eric

MySql database
Username = madashat_eric
Password = *******
database name = madashat_users
Table name = users

Table =

CREATE TABLE `users` (
`name` VARCHAR( 36 ) NOT NULL ,
`dob` VARCHAR( 10 ) NOT NULL ,
`email` VARCHAR( 36 ) NOT NULL ,
`website` VARCHAR( 72 ) NOT NULL ,
`username` VARCHAR( 36 ) NOT NULL ,
`password` VARCHAR( 36 ) NOT NULL
);
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ok, so create an html form that asks for username and password:

Code: Select all

<form name=&quote;MyForm&quote; action=&quote;validation.php&quote; method=&quote;post&quote;>
<input type=&quote;text&quote; name=&quote;username&quote;><br>
<input type=&quote;password&quote; name=&quote;password&quote;><br>
<input type=&quote;submit&quote; value=&quote;login&quote;>
then check against the database to make sure the credentials are valid:

Code: Select all

$query = &quote;select * from users where username = '&quote;.mysql_real_escape_string($_POSTї'username']).&quote;' and password = '&quote;.mysql_real_escape_string(md5($_POSTї'password'])).&quote;'&quote;;
$result = mysql_query($query)
  or die(mysql_error());
if($row = mysql_fetch_assoc($result))
  // valid stuff so send them somewhere else
else
  header(Location: login.php);
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Post by Gimpy »

what does my_real_escape_string do. manual didnt help me much
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

it just escapes the single quotes etc that cause sql headaches.

manual
Post Reply