Hi I am new to php and am trying to make a login page which I have used before and it worked last time. I am having trouble getting it to recognise the password. I know the password is correct as I have double, double, double checked in my sql tables. I suspect it may have something to do with the md5 password thingy but not sure. Any help would be much appreciated and I can finally get some sleep!
here is the code
login Page
<?php
/*
* Desc: Login program for the Admin section login
* using an existing LOGIN NAME and PASSWORD
*/
include("cnxion.inc");
switch (@$_GET['do'])
{
case "login":
$connection = mysql_connect($host, $user, $password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");
$sql = "SELECT username FROM admin
WHERE username='$_POST[fusername]'";
$result = mysql_query($sql)
or die("Couldn't execute query.");
$num = mysql_num_rows($result);
if ($num == 1)
// login name was found
{
$sql = "SELECT username FROM admin
WHERE username='$_POST[fusername]'
AND password=md5('$_POST[fpassword]')";
$result2 = mysql_query($sql)
or die("Couldn't execute query 2.");
$num2 = mysql_num_rows($result2);
if ($num2 > 0)
// password is correct
{
$_SESSION['auth']="yes";
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d h:i:s");
$sql = "INSERT INTO login (loginName,loginTime)
VALUES ('$logname','$today')";
mysql_query($sql) or die("Can't execute query.");
header("Location: tyre_admin_page.php");
}
else
// password is not correct
{
unset($_GET['do']);
$message="Your User Name
exists, but you have not entered the
correct password! Please try again.<br>";
include("adminlogin.inc");
}
}
elseif ($num == 0)
// login name not found
{
unset($_GET['do']);
$message = "The User Name you entered does not
exist! Please try again.<br>";
include("adminlogin.inc");
}
break;
}
?>
<?php
include_once("adminlogin.inc");
?>
Also here is the code for adminlogin.inc
<!-- INCLUDE form to login to the admin section -->
<form action= "admin_login.php?do=login" method="post">
<div align="center">
<?php
if (isset($message))
echo "<tr><td colspan='2'><b>$message</b>
</td></tr>";
?>
<label>Username:</label>
<input type="text" name="fusername"
size="20" maxsize="20" />
<br />
<br />
<label>Password:</label>
<input name="fpassword" type="password" id="fpassword" size="20" maxlength="20" />
<br />
<br />
<input name="log" type="submit" id="log" value="Login" />
</div>
</form>
<p> </p>
Thank You