Cool, I figured a few things out. First, my copy of the db object was not the problem, it works now. I think your suggestion to put in an else statement if a user is registered was the key. For some reason I never suspected that.
I think in order to disconnect from DB you have to first free the result sets and then call the diconnect method. Here is the code now that everything is working:
//this is the user login page for main entrance
//include necessary files
require("lib/SmartWind.php");
require("lib/DB.php");
require("lib/FormClass.php");
require("lib/dsn.php");
//validate the incoming field values
if(isset($_POST['submit'])) {
$fv = new FormValidator();
$fv->isEmpty("userName", "Enter a username");
$fv->isEmpty("userPass", "Enter a password");
$fv->isNotSymbol("userName", "Some values entered are forbidden");
$fv->isNotSymbol("userPass", "Some values entered are forbidden");
//Check to see if there are errors.
if($fv->isError()) {
//if errors exist, populate the array
$errors = $fv->getErrorList();
//register the error session
$_SESSION['VAL_ERROR'] = $errors;
header("location:login.php");
exit();
} else {
//clean up the variables
$userName = trim(htmlspecialchars($_POST['userName']));
$userPass = trim(htmlspecialchars($_POST['userPass']));
//connect to the database
$db = DB::connect($dsn);
if(DB::isError($db)) {
die ($db->getMessage());
}
//copy the connection
$db2 =& $db;
//check the result
$result = $db->query("SELECT user_id, username, password, AccountName, security_level, security_desc FROM user_login, lu_user_security WHERE user_login.security_level = lu_user_security.security_id AND user_login.username = '$userName' AND user_login.password = '$userPass'");
if(DB::isError($db)) {
die ($result->getMessage());
}
if($result->numRows() == 1) {
//get the result set
$row = $result->fetchRow(DB_FETCHMODE_ASSOC);
//create a session for valid user
if(!isset($_SESSION['USER_NAME'])) {
$_SESSION['WINDSTORM'] = 'WINDSTORM_USER12f8jGlKQa7bi2LcX4zDi';
$_SESSION['USER_NAME'] = $row['AccountName'];
$_SESSION['SEC_DESC'] = $row['security_desc'];
$_SESSION['SEC_LEVEL'] = $row['security_level'];
$_SESSION['USER_ID'] = $row['user_id'];
//update the database to show the login date and time
$update = $db2->query("UPDATE user_login SET visit_count = visit_count + 1, last_logged_on = null WHERE username = '$userName'");
if(DB::isError($db2)) {
die ($db2->getMessage());
}
} else {
header("location:default.php");
$result->free();
$update->free();
$db->disconnect();
$db2->disconnect();
exit();
}
//send the valid user to the default page, free results and disconnect
header("location:default.php");
$result->free();
$update->free();
$db->disconnect();
$db2->disconnect();
exit();
} else {
//regisiter a login error function
$_SESSION['LOGIN_ERROR'] = "LOGIN_ERROR";
//user login failed
//call smarty and display the form with an error message
$smarty = new SmartWind();
//register error sessions and assign them to smarty
$smarty->assign("LOGIN_ERROR", $_SESSION['LOGIN_ERROR']);
$smarty->assign("VAL_ERROR", $_SESSION['VAL_ERROR']);
//display the page
$smarty->display('main_nav.tpl');
$smarty->display('login_form.tpl');
$smarty->display('footer.tpl');
}
}
} else {
//call smarty and display the form
$smarty = new SmartWind();
//display the page
$smarty->display('main_nav.tpl');
$smarty->display('login_form.tpl');
$smarty->display('footer.tpl');
}
?>