<!DOCTYPE html>
<html lang="en">

<head>
    <title>Login</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/png" href="img/icons/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
    <link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
    <link rel="stylesheet" type="text/css" href="css/util.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body>
    <div class="limiter">
        <div class="container-login100">
            <div class="wrap-login100">
                <div class="login100-pic js-tilt" data-tilt>
                    <img src="img/img-01.png" alt="IMG">
                </div>
                <form class="login100-form validate-form">
                    <span class="login100-form-title">
                        Roytip Login
                    </span>
                    <div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
                        <input class="input100" type="text" name="Username" placeholder="Email">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-envelope" aria-hidden="true"></i>
                        </span>
                    </div>
                    <div class="wrap-input100 validate-input" data-validate="Password is required">
                        <input class="input100" type="password" name="password" placeholder="Password">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-lock" aria-hidden="true"></i>
                        </span>
                    </div>
                    <div class="container-login100-form-btn">
                        <button class="login100-form-btn" type="submit" name="submit" value="submit">
                            Login
                        </button>
                    </div>
                    <!-- <div class="text-center p-t-12">
                        <span class="txt1">
                            Forgot
                        </span>
                        <a class="txt2" href="#">
                            Username / Password?
                        </a>
                    </div> -->
                    <div class="text-center p-t-136">
                        <a class="txt2" href="/register">
                            Create your Account
                            <i class="fa fa-long-arrow-right m-l-5" aria-hidden="true"></i>
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php
	$servername = "localhost";
	$username = "dbAdmin";
	$password = "P@ss1234";
	$dbname = "projectweb";
	
	$conn = mysqli_connect($servername, $username, $password, $dbname);
	if (isset($_GET['submit'])){
		$users = $_GET['Username'];
		$Passs = $_GET['password'];
		$sql = "SELECT * FROM `USERS`";
		$result = mysqli_query($conn, $sql);
		$a=array();
		
		if (mysqli_num_rows($result) > 0) {
			while($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
				$a[$row[1]]=$row[2];
			}
			if (array_key_exists($users,$a)){
				if($Passs==$a[$users]){
					// print("<script language='javascript'>alert(\"สวัสดี \ $users \\ยินดีต้อนรับสู่เว็บไซต์ ร้อยทิป\");</script>");
					print("<script language='javascript'>window.location = '/';</script>");
				}else{
					print("<script language='javascript'>alert(\"พาสเวิร์ดของ \ $users \\ไม่ถูกต้อง\");</script>");
				}
			}
			else{
				print("<script language='javascript'>alert(\"ไม่มีผู้ใช้ \ $users \\ในระบบนี้\");</script>");
				
			}
		} else {
			echo "0 results";
		}}
	mysqli_close($conn);
?>
<!----------------------------------------------------------------JS---------------------------------------------------------------------------- -->
    <script src="vendor/jquery/jquery-3.2.1.min.js" type="9965159fe884f58a103521bc-text/javascript"></script>
    <script src="vendor/bootstrap/js/popper.js" type="9965159fe884f58a103521bc-text/javascript"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js" type="9965159fe884f58a103521bc-text/javascript"></script>
    <script src="vendor/select2/select2.min.js" type="9965159fe884f58a103521bc-text/javascript"></script>
    <script src="vendor/tilt/tilt.jquery.min.js" type="9965159fe884f58a103521bc-text/javascript"></script>
    <script type="9965159fe884f58a103521bc-text/javascript">
        $('.js-tilt').tilt({
            scale: 1.1
        })
    </script>
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-23581568-13" type="9965159fe884f58a103521bc-text/javascript"></script>
    <script type="9965159fe884f58a103521bc-text/javascript">
        window.dataLayer = window.dataLayer || [];

        function gtag() {
            dataLayer.push(arguments);
        }
        gtag('js', new Date());

        gtag('config', 'UA-23581568-13');
    </script>
    <script src="js/main.js" type="9965159fe884f58a103521bc-text/javascript"></script>
    <script src="https://ajax.cloudflare.com/cdn-cgi/scripts/a2bd7673/cloudflare-static/rocket-loader.min.js" data-cf-settings="9965159fe884f58a103521bc-|49" defer=""></script>

</body>
</html> 