Page 1 of 1

comparing 2 database fields

Posted: Sat Jun 14, 2003 9:37 am
by danco
Hi,

I need to make a user login page where they just enter the details (username and password) and it carry's those variables to the login process page. I can dot hat but i need to know, without using sessions or anything how to get the username form the database and then compare the stored password for it.

I seem to always be getting pages showing me i need to use sessions but i wish not to use them on this occasion.

I would be very gratefull for some help in creating the login process php page.

Thanks,

Danco

Posted: Sat Jun 14, 2003 10:59 am
by automaton
This a somewhat simple. There are many ways to skin a cat.
If you are not going to use session variables you will need to check that a user is logged in on every page.
This isn't guaranteed to be error free - use at own risk.
Good Luck!

Code: Select all

<?php if($_POST['submit']=="") { ?>

Code: Select all

&lt;form method="post" action=""&gt;
Login Page - Form with three inputs
Username:&lt;input type="text" name="username"&gt;&lt;br&gt;
Password:&lt;input type="password" name="password"&gt;&lt;br&gt;
&lt;input type="submit" name="submit" value="submit"&gt;

Code: Select all

} else if($_POST['submit']=="submit") { 
$query = "SELECT * FROM db.table " .
              "WHERE " .
              "username = " . $_POST['username'] . " " .
              "AND " .
              "password = " . $_POST['password'] ;
$connection = mysql_connect(your db stuff here) ;
$db = mysql_select_db("your_db_name") ;
$result = mysql_db_query($query,$connection) ;
$row = mysql_fetch_assoc($result)
if ($row<>"") {
 header ("Location: http://abc.def.com/login.php") ;
} else { 
 header ("Location: http://abc.def.com/you_are_logged_in.php") ;
} // end of row conditional
}// end of post conditional