Page 1 of 1

Login Script

Posted: Tue Jul 05, 2005 1:14 pm
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
);

Posted: Tue Jul 05, 2005 3:23 pm
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);

Posted: Tue Jul 05, 2005 4:59 pm
by Gimpy
what does my_real_escape_string do. manual didnt help me much

Posted: Tue Jul 05, 2005 5:22 pm
by Burrito
it just escapes the single quotes etc that cause sql headaches.

manual