Hey people,
looking for a bit of help finding the problem with my code.
What its supposed to do is collect the username and password from a form and then check that the user exists and the password is correct... - it does this fine and creates a session for the user.
Problem is when I try to use the username and password variables again to get the results from the database it doesn't work and im not sure why.
heres my code:
<?php
// include function files for this application
require_once('functions.php');
//create short variable names
$username = $_POST['username'];
$password = $_POST['password'];
// they have just tried logging in
if ($username && $password) {
// check if username is unique
$result = mysql_query("select * from users where username='$username' and password = sha1('$password')")
or die ("Could not log you in.");
if (mysql_num_rows($result)) {
$_SESSION['valid_user'] = $username;
}
else {
echo 'Login Failed. <br />[<a href=login.php>login</a>]';
exit;
}
}
echo 'Logged in as '.$_SESSION['valid_user'];
//THIS IS THE PART IM HAVING TROUBLE WITH ===================
$result = mysql_query("select * from users where username='$username' and password = sha1('$password')")
or die ("Couldn't Connect to Database.");
// now display the results returned
$row= mysql_fetch_array($result);
echo '<br><br><a href="'.$row['sitedir'].'/Admin/">Continue to '.$row['sitename'].'s Admin Area</a><br><br>';
//==================================================
include('member-menu.php');
?>
any help welcome,
Thanks.