registerAction.php 1.02 KB
<?php
session_start();
if($_SESSION['name']){
}else header('Location: index.php');
require_once 'include/DB_Functions.php';
$db = new DB_Functions();

if (isset($_POST['name'])&& isset($_POST['username']) && isset($_POST['password'])) {

    // receiving the post params
    $name = $_POST['name'];
    $username = $_POST['username'];
    $password = $_POST['password'];

    // check if user is already existed with the same login
    if ($db->isUserExisted($username)) {
        // user already existed
        die ("User already existed with " . $username);
       
    } else {
        // create a new user
        $user = $db->storeUser($name, $username, $password);
        if ($user) {
            // user stored successfully
             echo "User saved!" ."<p>". "<a href='workArea.php'>Click here to continue</a>";
        } else {
            // user failed to store
            die("Unknown error occurred in registration!");
        }
    }
} else {
    
    die ("Required parameters (name, username or password) is missing!");
}
?>