Hi Nick,
First a few comments on your programming style... Everything looks good from a logic standpoint. You're missing a few dollar signs. You should be seeing errors because of these. What level is error_reporting set to in php.ini?
Some suggestions:
1.) As I mentioned previously you aren't reporting database errors. Use mysql_error() to retrieve the error text, if any, from mysql. PHP won't throw an error if nothing's wrong syntax-wise. This will likely tell you what exactly is wrong with your sql. If there is no error text to be had, then something isn't right with the data itself.
2.) If you can avoid creating a variable then don't create one. Memory has to be allocated for each new variable you create.
3.) As I mentioned in my last post (but didn't explain why) don't use session_register(). Are you using PHP < 4.1.0? If you are and can do nothing about it then this is O.K. otherwise use the $_SESSION superglobal. Superglobals are like any other variables but exist for certain classifications of data and may contain preset values depending on which category is being used. Superglobals are not subject to normal variable scoping rules, which means you can use them inside of functions or classes without passing as an argument.
Use the $_POST superglobal instead of $HTTP_POST_VARS.. the latter is deprecated and future versions of PHP may not support it. A $_xxxx variable exists for every $HTTP_xxx_VARS.
SEE:
http://www.php.net/manual/en/languag...predefined.php
And Nik's explaination of why session_register is bad:
http://p2p.wrox.com/topic.asp?TOPIC_ID=2052
4.) Assuming that you are going to use a database for more than just the login, make only a single database connection per script execution whenever possible. Building a database connection is resource intensive so its best to do it only once at the beginning of a script and close it at the end of a script.
So all that being said the following is how I would suggest structuring your code.
<?php include('../Connections/dreamweaver_hotel_admin.php'); ?>
<?php
function db_connect()
{
// connect to mysql server
// In your original code you left off the dollar sign in your check
if (!$GLOBALS['mysql'] = mysql_connect('localhost', 'root', 'fabric')
{
return FALSE;
}
// connect to database
// Again, you left off a dollar sign.
// But there's no need to create a variable there anyway.
if (!mysql_select_db('dwhotel'))
{
return FALSE;
}
return TRUE;
}
function check_login()
{
// Get form data
// How was the password stored in the DB?
// If you used encryption to store it then you must use encryption to retrieve it.
if (!$result = mysql_query("SELECT * FROM users WHERE userName = '{$_POST['userName']}' AND password = '{$_POST['password']}'", $GLOBALS['mysql']))
{
// Obviously you don't want to show errors to your users
// but when you're developing you need to know what's up.
echo mysql_errno().': ';
echo mysql_error()."<br />\n";
return 'Cannot run query';
}
// check that we have a record returned
if (mysql_num_rows($result) < 1)
{
return 'User name or password not recognized';
}
// get user status from returned record
$userRecord = mysql_fetch_array($result);
return $userRecord['status'];
}
?>
<?php
// Initiate a database connection.
if (!db_connect())
{
echo 'Unable to initiate a connection to the database.<br />';
echo 'MySQL said: '.mysql_error().'<br />';
}
//this section is only run when the form has been submitted
if (isset($_POST['Submit']) && $_POST['Submit'] == 'Login')
{
session_start();
// check whether the login details are correct, and put
// the user status into a session variable.
$statusCheck = check_login();
if ($statusCheck == 'Admin' || $statusCheck == 'Staff')
{
$_SESSION['statusCheck'] = $statusCheck;
header('Location: menu.php');
}
else
{
echo $statusCheck;
}
}
?>
// Snip Snip
I'm sure that's a lot to digest.. but should be very straight forward. If you run mysql error reporting and still are not getting results then we'll talk more on troubleshooting.
hth,
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::