I have a a script that does inserts into the customer table, then encrypts a password and inserts the user information into the users table then logs the user in and redirects them to a confirmation page. Everything works except that the user does not get logged in. I have a function called show log in which outputs whether a user is logged in or logged out to the page. The problem I am having is that I dont appear to have a working login script and the email address is not outputing to the page as it should.
This is my showLogin() function.
function showLogin(&$xtpl)
{
// Is the user logged in?
if (isset($_SESSION["loginUsername"]))
{
$logedin = $_SESSION["loginUsername"];
$xtpl->assign("logedin", $logedin);
$xtpl->parse("main.logedin.logedin");
}
else
$xtpl->parse("main.logedin.logedout");
$xtpl->parse("main.logedin");
}
This is the insert script where I create the user and automatically log the user into the system.
if ($formVars["custType"] == "Customer")
{
// Get the customer id that was created
$custID = @ mysql_insert_id($connection);
// Use the first two characters of the
// email as a salt for the password
$salt = substr($formVars["loginUsername"], 0, 2);
// Create the encrypted password
$stored_password = crypt($formVars["loginPassword"], $salt);
// Insert a new user into the user table
if (!(@ mysql_query ("INSERT INTO tbl_users set " .
"user_name = \"" . $formVars["loginUsername"] . "\", " .
"password = \"" . $stored_password . "\", " .
"cust_id = \"" . $custID . "\"", $connection)))
// if the database insert is not successful call the error function
showerror();
// Log the user into their new account
isset($_SESSION["loginUsername"]);
$loginUsername = $formVars["loginUsername"];
}
// Clear the formVars so a future <form> is blank
unset($_SESSION["formVars"]);
unset($_SESSION["errorString"]);