<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Simple Database Connection</title>
</head>
<body bgcolor="white">
<?php
$connection = mysql_connect("localhost", "root", "phpmysql");
$select_db = mysql_select_db("procdumy", $connection);
$query = mysql_query ("SELECT username, password FROM users", $connection);
if(isset( $_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$name = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT password FROM users WHERE username = '$username'")or die(mysql_error());
//$check = mysql_query("SELECT cust_username,cust_pswrd FROM customer WHERE cust_username = '$cust_username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
//else
//{
//header("Location: welcome.php");
//}
}
}
//if the login form is submitted
if (isset( $_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(! $_POST['name'] | ! $_POST['pass']) {
die('You did not fill in a required field.<a href=login.php>back</a>');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['email'] = ( $_POST['email']);
$_POST['email'] = addslashes( $_POST['email']);
}
$check = mysql_query("SELECT password FROM users WHERE username = '". $_POST['name']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database.
<a href=reg.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes( $_POST['pass']);
$info['password'] = stripslashes($info['passwordd']);
$_POST['pass'] = md5( $_POST['pass']);
///*
//gives error if the password is wrong
//if ( $_POST['pass'] != $info['password']) {
//if (md5( $_POST['pass'] ,$info['cust_pswrd'] ==$info['cust_pswrd'])){
if ( $_POST['pass']!= $info['cust_pswrd']) {
echo $_POST['pass']."<br>\n";
echo $info['password']."<br>\n";
die('Incorrect password, please try again.<a href=login.php>Click Here </a>');
}
else
{
//*/
// if login is ok then we add a cookie
$_POST['name'] = stripslashes( $_POST['name']);
$hour = time() + 3600;
//setcookie(ID_my_site, $_POST['name'], $hour);
//setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
header("Location: welcome.php");
}
}
}
else
{
// if they are not logged in
?>
<TR>
<TD><IMG height=115 src="resources/visitorsBanner.png" width="100%"></TD>
</TR>
<form action="<?php echo $_SERVER['../test/PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="name" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr>
<td colspan="2" align="right"> <input type="submit" name="submit" value="Login">
<input type="Reset" value="Clear Form" ></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
I am trying to log on with this code everything else works but the password say its incorrect.on the database it it 32bits long I cant see where my proble is.
Any bright idea for me on what s wrong??
tried all the commented codes.
Thanx
I am trying to log on with this code everything else works but the password say its incorrect.on the database it it 32bits long I cant see where my proble is.
Any bright idea for me on what s wrong??
tried all the commented codes.
Thanx