Esempio n. 1
0
function checkLogin($loginUsername, $loginPassword, $connection)
{
    if (authenticateUser($loginUsername, $loginPassword, $connection)) {
        registerLogin($loginUsername);
        // Clear the formVars so a future <form> is blank
        unset($_SESSION["loginFormVars"]);
        unset($_SESSION["loginErrors"]);
        header("Location: " . S_MAIN);
        exit;
    } else {
        // Register an error message
        $_SESSION["message"] = "Username or password incorrect. Login failed.";
        header("Location: " . S_LOGIN);
        exit;
    }
}
Esempio n. 2
0
        trigger_error($result->getMessage(), E_USER_ERROR);
    }
    // Find the max cust_id
    $result = $connection->query("SELECT max(cust_id) FROM customer");
    if (DB::isError($result)) {
        trigger_error($result->getMessage(), E_USER_ERROR);
    }
    $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
    // Work out the next available ID
    $cust_id = $row["max(cust_id)"] + 1;
    // Insert the new customer
    $query = "INSERT INTO customer VALUES ({$cust_id}, \n            '{$_SESSION["custFormVars"]["surname"]}', \n            '{$_SESSION["custFormVars"]["firstname"]}',  \n            '{$_SESSION["custFormVars"]["initial"]}', \n            {$_SESSION["custFormVars"]["title_id"]}, \n            '{$_SESSION["custFormVars"]["address"]}', \n            '{$_SESSION["custFormVars"]["city"]}', \n            '{$_SESSION["custFormVars"]["state"]}', \n            '{$_SESSION["custFormVars"]["zipcode"]}', \n            {$_SESSION["custFormVars"]["country_id"]}, \n            '{$_SESSION["custFormVars"]["phone"]}', \n            '{$_SESSION["custFormVars"]["birth_date"]}')";
    $result = $connection->query($query);
    if (DB::isError($result)) {
        trigger_error($result->getMessage(), E_USER_ERROR);
    }
    // Unlock the customer table
    $result = $connection->query("UNLOCK TABLES");
    if (DB::isError($result)) {
        trigger_error($result->getMessage(), E_USER_ERROR);
    }
    // As this was an INSERT, we need to INSERT into the users table too
    newUser($_SESSION["custFormVars"]["loginUsername"], $_SESSION["custFormVars"]["loginPassword"], $cust_id, $connection);
    // Log the user into their new account
    registerLogin($_SESSION["custFormVars"]["loginUsername"]);
}
// Clear the custFormVars so a future form is blank
unset($_SESSION["custFormVars"]);
unset($_SESSION["custErrors"]);
// Now show the customer receipt
header("Location: " . S_CUSTRECEIPT);