<?php
require_once("requires.php");
// if logging in
$msg = '';
$_SESSION['user'] = array();
if (isset($_POST) && isset($_POST['username'])) {
    $usersObj = new Table("user");
    $_POST['username'] = mysql_escape_string($_POST['username']);
    $_POST['password'] = mysql_escape_string($_POST['password']);
    $user = $usersObj->findWhere("`cardnumber` = '{$_POST['username']}' AND `password` = '{$_POST['password']}' ");
    if (!empty($user)) {
        $_SESSION['user'] = $user;
        header("Location:dashboard.php");
    }
    else {
        $msg = "<br> Invalid user!";
    }
}
if (!empty($_SESSION['user'])) {
        $_SESSION['user'] = $user;
        header("Location:dashboard.php");
    }

require_once('header.php');
?>

<div id="page">
    <div class="container">
        <div class="wrapper">
            <div class="home-content">
                <h3>Subscribe to our new <br><span class="red">payement card!</span><?php echo $msg;?></h3>
                <div class="pure-g-r">
                    <div class="pure-u-1-3 form">
                        <form action="." method="post">
                            <input type="text" placeholder="Username" name="username" id="username">
                            <input type="password" placeholder="Password" name="password" id="password">
                            <input type="submit" value="Sign in">
                        </form>
                        <p class="sign-up">Don’t have an account? <a class="red strong" href="register.php">Sign Up!</a></p>
                    </div>
                    <div class="pure-u-1-3 text">
                        <div class="inner">
                            <h3 class="first">A new easy, fast, practical, online method to help you purchase any good from any franchise.</h3>
                            <h3>And don't forget...<br>It's COOL!</h3>
                        </div>
                    </div>
                    <div class="pure-u-1-3 image">
                        <img src="img/home-bg.png" alt="" >
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<?php require_once('footer.php'); ?>

