yes its me (the noob) again.
i stare at this code and i cant see an error. it keeps telling me i "could not log me in" i am using the right password and user name but it still doesnt work. it does throw any errors it just says it cant log me in... can anyone tell me why it doesnt work?
<?php
session_start();
if (isset($POST['username']) && isset($POST['password']))
{
// if the user has just tried to log in
$username = $POST['username'];
$password = $POST['password'];
$dbh = @mysql_connect('localhost', 'database', 'password');
if (!$dbh)
{
echo( "<p>Unable to connect to the " . "database server at this time.</p>" );
exit();
}
if (! mysql_select_db('table') )
{
echo( "<p>Unable to locate the Member " . "database at this time.</p>" );
exit();
}
$query = 'select * from members '
."where username='$username' "
." and password=SHA1('$password')";
$result = mysql_query($query);
if ($result->num_rows >0 )
{
// if they are in the database register the user id
$SESSION['valid_user'] = $username;
}
mysql_close($dbh);
}
?>
<html>
<body>
<h1>Home page</h1>
<?
if (isset($SESSION['valid_user']))
{
echo 'You are logged in as: '.$_SESSION['valid_user'].' <br />';
echo '<a href="logout.php">Log out</a><br />';
}
else
{
if (isset($username))
{
// if they've tried and failed to log in
echo 'Could not log you in.<br />';
}
else
{
// they have not tried to log in yet or have logged out
echo 'You are not logged in.<br />';
}
// provide form to log in
echo '<form method="post" action="index2.php">';
echo '<table>';
echo '<tr><td>Username:</td>';
echo '<td><input type="text" name="username"></td></tr>';
echo '<tr><td>Password:</td>';
echo '<td><input type="password" name="password"></td></tr>';
echo '<tr><td colspan="2" align="center">';
echo '<input type="submit" value="Log in"></td></tr>';
echo '</table></form>';
}
?>
<br />
<a href="index3.php">Members section</a>
</body>
</html>