OK! I have this logon script which does this if the form is submitted:
// If the user has submitted content to the login form
if(isset($_POST[submit])){
// Extract posted vars
extract($_POST);
// Log user in...
// Start session
session_start();
// Set username and password as session vars
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
// Connect to DB
if($mysqlPassword != ''){
// Connect to DB with password
$mysqlConnect = mysql_connect($mysqlHost, $mysqlUser, $mysqlPassword);
}
else{
// Connect without password
$mysqlConnect = mysql_connect($mysqlHost, $mysqlUser);
}
// Select DB
mysql_select_db($mysqlDB);
// Prepare query
$checkUser = "SELECT password FROM admin WHERE username = '" . $_SESSION['username'] . "'";
// Run query
$checkUserResults = mysql_query($checkUser);
echo '$checkUserResults: ' . $checkUserResults;
// Make results into an associative array
$checkUserArray = mysql_fetch_assoc($checkUserResults);
printf($checkUserArray);
// Make a var containing no. of rows
$numRows = mysql_num_rows($checkUserResults);
// Check for valid Username and password
if($numRows == "1" && $_SESSION['password'] == $checkUserArray["password"]) {
$validUser = 1;
$message = 'Logged in as ' . $_SESSION['username'];
header("Location: index.php?message=$message");
}
else {
$validUser = 0;
$message = 'Incorrect teamname or password. Please try again.<br />';
header("Location: login.php?message=$message");
session_unset();
session_destroy();
}
}
As you can see, I have made the script debug, this is the returned content (after form submition)
$checkUserResults:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/thepeccavi.co.uk/bsc/teamadmin/login.php on line 43
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/thepeccavi.co.uk/bsc/teamadmin/login.php on line 48
Warning: Cannot modify header information - headers already sent by (output started at /home/www/thepeccavi.co.uk/bsc/teamadmin/login.php:40) in /home/www/thepeccavi.co.uk/bsc/teamadmin/login.php on line 59
Do you know what I am doing wrong?