Need help writing a register.php script?
<p>Here's my working checkLogin.php script that allows the user to successfully sign in to the web app I'm developing for a college project:</p>

<pre><code>require_once 'User.php';

require_once 'UserDAO.php';

session_start();

$username = $_REQUEST['username'];

$password = $_REQUEST['password'];

$userDAO = new UserDAO();

$user = $userDAO-&gt;getUserByUsername($username);

$valid = false;

if ($user != null) {

    if ($user-&gt;getPassword() == $password) {

        $valid = true;

    } else {

        $errorMessage = "Invalid password";

    }

} else {

    $errorMessage = "Invalid username";

}

header("Content-type: application/json");

if ($valid) {

    if ($user-&gt;getRole() == 'admin') {

        $nextPage = 'adminHome.php';

    } else {

        $nextPage = 'home.php';

    }

    $_SESSION['user'] = $user;

    echo json_encode(array(

        'status' =&gt; "success",

        'userid' =&gt; $user-&gt;getStudentId(),

        'next' =&gt; $nextPage

    ));

} else {

    if ($errorMessage != null) {

        echo json_encode(array(

            'status' =&gt; "error",

            'message' =&gt; $errorMessage

        ));

    }

}
</code></pre>

<p>Problem is, I need the register.php to allow users to register an account. I'm of the opinion that the register script should reflect the checkLogin script but I'm at a loss as to how to write the register.php script.
So if anybody know what the register.php script should look like please help me out. Project is due in on Feb. 22nd!
Just in case, here's how I have the register.php script looking at this moment in time:</p>

<pre><code>require_once 'User.php';

require_once 'UserDAO.php';

session_start();

$username = $_REQUEST['username'];

$password = $_REQUEST['password'];

$userDAO = new UserDAO();

$user = $userDAO-&gt;getUserByUsername($username);

$password = $userDAO-&gt;getUserByPassword($password);

$valid = false;

if ($user != null) {

    $errorMessage = "User already exists";

} else {

    $valid = true;

}

if ($password != null) {

    $errorMessage = "Password already exists";

} else {

    $valid = true;

header("Content-type: application/json");

    if ($valid) {

        if ($user-&gt;getRole() == 'admin') {

            $nextPage = 'adminHome.php';

        } else {

            $nextPage = 'home.php';

        }

        $_SESSION['user'] = $user;

        echo json_encode(array(

            'status' =&gt; "success",

            'userid' =&gt; $user-&gt;getStudentId(),

            'next' =&gt; $nextPage

        ));

    } else {

        if ($errorMessage != null) {

            echo json_encode(array(

                'status' =&gt; "error",

                'message' =&gt; $errorMessage

            ));

        }
    }
</code></pre>
