Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="inv.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- </head>
- <body class="body_sign_in">
- <div class="container">
- <div class="row">
- <div class="col-xs-6 col-xs-offset-3">
- <div class="well" id="sign_in_form">
- <h1>Please Sign In</h1>
- <form action="#" method="post">
- <div class="form-group">
- <label for="username">Username:</label>
- <input class="form-control" type="text" name="username">
- </div>
- <div class="form-group">
- <label for="password">Password:</label>
- <input class="form-control" type="text" name="password">
- </div>
- <button class="btn btn-success sign_in_btn" type="submit" name="submit">Sign In</button>
- </form>
- </div>
- </div>
- </div>
- </div>
- <!-- PHP Section -->
- <?php
- try {
- $host = "localhost";
- $dbname = "inventory";
- $username = "root";
- $pwd = " ";
- $conn = new PDO("mysql:host=$host; dbname=$dbname", $username, $pwd);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // echo "Connected Successfully!";
- }
- catch (PDOException $e) {
- echo "Connection failed: " . $e->getMessage();
- }
- if (isset($_POST['submit'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- //set Session username variable
- $_SESSION['username'] = $username;
- // echo "Session variable is set!";
- // Check if username field is set
- if (empty($username)) {
- echo "<div class='container'><div class='row'><div class='col-xs-6 col-xs-offset-3'>";
- echo "<h3>Oops! Username is empty.</h3>";
- echo "</div></div>";
- exit();
- }
- // Check if password field is set
- if (empty($password)) {
- echo "<div class='container'><div class='row'><div class='col-xs-6 col-xs-offset-3'>";
- echo "<h3>Oops! Password is empty.</h3>";
- echo "</div></div>";
- exit();
- }
- // Query database for matching username and password
- $sql = "SELECT * FROM login WHERE username = :username AND password = :password";
- $statement = $conn->prepare($sql);
- $statement->execute(array (':username' => $username,':password' => $password));
- $count = $statement->rowCount();
- if ($count == 0) {
- echo "<div class='container'><div class='row'><div class='col-xs-6 col-xs-offset-3'>";
- echo "<h3>Sorry! Username and/or password is invalid. Try again!</h3>";
- echo "</div></div>";
- exit();
- }
- else if ($count > 0) {
- header('location: http://localhost/Inventory/inv_home.php');
- }
- }
- ?>
- <!-- PHP Section -->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement