Ok to line it all off I came to the conclusion that my login wont work at all! I don't know what the problem is becuase ive revised the code about 50 times!
Here is the code for the login page:
<?php include("../include/dreamweaver_hotel_admin.php"); ?>
<?php
// This section is only run when the form has been submitted
if($HTTP_POST_VARS['Submit']=='Login'){
session_start();
// Check whether the login details are correct, and put
// the user status into a session variable.
$statusCheck = check_login($HTTP_POST_VARS);
if ($statusCheck == "Admin" || $statusCheck == "Staff"){
session_register("statusCheck");
header("Location: /memonly/index.php");
}
}
?>
<?
function check_login($formdata) {
// This section queries the users table, and searches for
// the username and password that were supplied. If the
// user is not found, an error is returned. If the user
// details are correct the users status is returned.
// Setup MySQL Connection variables, set as correct for your system.
$dbhost = "";
$dbuser = "";
$dbpassword = "";
$db = "";
// Get Form Data
$form_data = trim($formdata);
$user = $form_data['username'];
$password = $form_data['password'];
// Connect to the mySQL Server
$mysql = mysql_connect($dbhost, $dbuser, $dbpassword);
if(!$mysql) {
$error = "Cannot connect to Database Host";
return($error);
}
// Open the mySQL Database
$mysqldb = mysql_select_db($db);
if(!$mysqldb) {
$error = "Cannot open Database";
return($error);
}
// Query Database
$myquery = "SELECT * FROM users WHERE username = '" . $user . "' AND password = '" . crypt($password,"DWMXPHP") . "'";
$result = mysql_query($myquery);
if (!$result){
$error = "Cannot run Query";
return($error);
}
// Check that we have a record returned
$numRows = mysql_num_rows($result);
if ($numRows < 1){
$error = "User name or password not recognised";
return($error); }
// Get user status from returned record
$userRecord = mysql_fetch_array($result);
$status = $userRecord["status"];
return($status);
}
?>
Heres the code for the logged in page:
<?php
session_start();
// If the user logs out, destroy their session
if($HTTP_GET_VARS['action']=='logout'){
session_unregister("statusCheck");
session_destroy(); }
// If no session is set, redirect to login.php
if (!session_is_registered("statusCheck"))
header("Location: [url]http://www.clanph.net/login_redirect.php[/url]");
?>
The error I always get back is "User name or Password not recognised" but its in the damn database. And yes its set up correctly! Can anyone see any errors in the code?