<?php


require_once('config.php');





if(($response["error"] == true))
{
    echo(json_encode($response));
}




if((isset($_POST["request"])) && ($_POST["request"] == "signup"))
{
    $logs       =   array();
    $firstname  =   "";
    $lastname   =   "";
    $email      =   "";
    $password   =   "";

    if((empty($_POST["firstname"])))
    {
        $response["error"]      =   true;
        $response["error_msg"]  =   "An Error Occurred. First Name is required";
    }
    else
    {
        $firstname  =   $_POST["firstname"];
    }

    if(($response["error"] == false))
    {
        if((empty($_POST["lastname"])))
        {
            $response["error"]      =   true;
            $response["error_msg"]  =   "An Error Occurred. Last Name is required";
        }
        else
        {
            $lastname  =   $_POST["lastname"];
        }
    }

    if(($response["error"] == false))
    {
        if((empty($_POST["email"])))
        {
            $response["error"]      =   true;
            $response["error_msg"]  =   "An Error Occurred. Email is required";
        }
        else
        {
            $email  =   $_POST["email"];
        }
    }

    if(($response["error"] == false))
    {
        if((empty($_POST["password"])))
        {
            $response["error"]      =   true;
            $response["error_msg"]  =   "An Error Occurred. Password is required";
        }
        else
        {
            $password  =   $_POST["password"];
        }
    }

    if(($response["error"] == false))
    {
        $sql = "    INSERT INTO users (firstname, lastname, email_address, phone_no, password, role) 
                    VALUES (?, ?, ?, null , ?, 'customer')";
        $stmt = $db->prepare($sql); 
        $stmt->bind_param("ssss", $firstname, $lastname, $email, $password);
        $result     =   $stmt->execute();
        if(($result))
        {
            $response["message"]    =   "Your account has been created in the system. Please login to continue";
        }
        else
        {
            $response["error"]      =   true;
            $response["error_msg"]  =   "An Error Occurred while creating the account. Please try again later";
        }
    }

    if(($response["error"] == false))
    {
        $response["R_URL"]  =   $base_url."signin/";
    }
    echo(json_encode($response));

}







































?>