<?php
session_start();
require 'data/func.php';
$error = '0';

if (isset($_POST['submitBtn'])) :
    // Get user input
    $username = isset($_POST['username']) ? $_POST['username'] : '';
    $password = isset($_POST['password']) ? $_POST['password'] : '';

    // Try to login the user
    $error = loginUser($username, $password);
endif;
?>

<?php if ($error != '') : ?>

    <form action="<?= $_SERVER['PHP_SELF']; ?>" method="post" name="loginform">

        Username:<input class="text" name="username" type="text"  /><BR>
        Password:</td><td> <input class="text" name="password" type="password" /><br>
            <input class="text" type="submit" name="submitBtn" value="Login" />

    </form>

    <?php
endif;
if (isset($_POST['submitBtn'])) :
    ?>

    <?php
    if ($error == '') :
        ?>
        <script type="text/javascript"><!--window.location = "cp.php"//--></script>
        <?php
    
    else:
        echo $error;
    endif;
    ?>
    <br/><br/><br/></td></tr></table>

    <?php
endif;
?>

</body>   
