Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <style type="text/css">
- </style>
- <title></title>
- </head>
- <body>
- <?php
- $servername = "localhost"; //indicates which server to connect to
- $db = "assignment"; //indicates which db to access
- $username = "usertblOne"; //indicates which user to connect to, this depends on the db
- $password = "root123"; //password for the user above
- $userName = $_POST['userName']; //collects the post data from the userName box
- $userPass = $_POST['userPass']; //collects the post data from the userPass password box
- $conn = new mysqli($servername, $username, $password, $db); //stores the connection to the database
- if($conn->connect_error){ //run a check on whether an error occurs or not
- die("Connection Failed: " . $conn->connect_error); //print the error out
- }
- $query="SELECT * FROM users WHERE username='$userName' and password='$userPass'"; //stores the SQL that we will execute later
- $result = $conn->query($query); //store the result of the query and at the same time, executing the query.
- $rowCount = $result->num_rows; //storing the amount of rows that the SELECT has found
- if ($rowCount > 0){ //if rowcount is greater than 0, means there was a result found in the database
- // Successful Login
- session_start();
- $_SESSION['lgnSuccess'] = array("Login confirmed");
- include('webstats.php');
- header('Location: ../blog/index.php'); //Takes user to the next stage of this php project - the main page of the blog
- }else{
- $date = date("jS \of F Y h:i:s A");
- $myfile = fopen("ErrorLog.txt", "a");
- fwrite($myfile, $date . " " . "Login attempt failure on user: " . $userName .PHP_EOL);
- fclose($myfile);
- session_start(); //open up a session
- $_SESSION['errors'] = array("Your username or password was incorrect."); //create a session and call it errors
- header('Location: ./index.php'); //returns user to the original login page.
- // Unsuccessful Login
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment