Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.61 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Test Login Page</title>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <link rel="stylesheet" href="css/register.css" />
  6. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  7. <link rel="stylesheet" href="css/index.css" />
  8. <link rel="stylesheet" href="css/styles.css" />
  9. <link href='https://fonts.googleapis.com/css?family=Raleway:400,500,300,600' rel='stylesheet' type='text/css'>
  10. </head>
  11. <?php
  12.     //These lines create all the required variables and sets their default values  
  13.     $servername = "127.0.0.1";
  14.     $username = "root";
  15.     $password = "";
  16.     $dbname = "accounts";
  17.     $error = 0;
  18.     $emailErr = $passErr = $success = $email = $pass = $user = "";
  19.     $row = "";
  20.    
  21.     //This line creates the variable that will be used to connect to the database
  22.     $conn = new mysqli($servername, $username, $password, $dbname);
  23.    
  24.     //Checks the connection to the database
  25.     if ($conn->connect_error) {
  26.        
  27.     //If the connection fails, an error message is produced describing the error
  28.         die("Connection failed: " . $conn->connect_error . "/nPlease try again. If it still doesn't work, copy the error message and send it to cjbrennan2701@gmail.com");
  29.     }
  30.    
  31.     include "navBar.php";
  32.    
  33.     //When the user clicks submit on the form below, the following indented code runs
  34.     if ($_SERVER["REQUEST_METHOD"] === "POST") {
  35.        
  36.     //If the user hasn't entered anything in the email box, an error message is produced
  37.         if (empty($_POST["email"])){
  38.             $emailErr = "Please enter an email address";
  39.             $error = 1;
  40.         } else {
  41.     //Otherwise, their input is stored as $email
  42.             $email = $_POST["email"];
  43.         }
  44.        
  45.     //If the user hasn't entered anything in the password box, an error message is produced
  46.         if (empty($_POST["password"])){
  47.             $passErr = "Please enter a password";
  48.             $error = 1;
  49.         } else {
  50.  
  51.     //Otherwise, their input is stored as $pass
  52.         $pass = $_POST["password"];
  53.         }
  54.        
  55.     //If no initial errors are found, the user's input is then used to search the database
  56.         if($error != 1){
  57.  
  58.         //The database is then searched for matching email and password combinations
  59.             $sql = "SELECT * FROM testTable";
  60.            
  61.         //The number of results from the query is stored as $result
  62.             $result = mysqli_query($conn, $sql);
  63.            
  64.         //If the query was successful, there will only be one result
  65.             if (mysqli_num_rows($result) > 0) {
  66.                
  67.             //The values associated with the record found is stored in the array $row
  68.                 while($row = mysqli_fetch_assoc($result)) {
  69.                    
  70.                 //A session is started in the navigation bar using session_start() to allow the use of $_SESSION
  71.                    
  72.                 //The global variable $_SESSION["id"] has the user's id stored
  73.                     $_SESSION["id"] = $row["id"];
  74.                    
  75.                 //The user's first name is stored in the global variable $_SESSION["firstN"]
  76.                     $_SESSION["firstN"] = $row["firstN"];
  77.                    
  78.                     $_SESSION["surn"] = $row["surn"];
  79.                    
  80.                     $_SESSION["email"] = $row["email"];
  81.                    
  82.                     if (is_null($row["phone"])){
  83.                         $_SESSION["phone"] = "Not entered";
  84.                     } else {
  85.                         $_SESSION["phone"] = $row["phone"];
  86.                     }
  87.                 }
  88.                
  89.             //The user is presented with a greeting message using the assigned $_SESSION["firstN"]
  90.                 $success = "Welcome, " . $_SESSION["firstN"];
  91.            
  92.             //If a match isn't found, an error message is displayed to the user
  93.             } else {
  94.                 $success = "Email and password combination not found, please try again";
  95.             }
  96.         }
  97.     }
  98.    
  99. ?>
  100.  
  101. <body>
  102. <div class="container-fluid">
  103. <div class="row">
  104. <div class="col-md-3"></div>
  105. <div class="col-xs-12 col-md-6" style="text-align:center">
  106. <!-- This line creates a form which runs the PHP code above when the user clicks submit -->
  107. <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'])?>" method="post" name="login">
  108.   <p>Please enter your username and password</p>
  109.  
  110.   <!-- These lines create a box allowing the user to input their email address and space for  any errors being displayed -->
  111.   E-mail:
  112.   <input type="text" name="email" id="email">
  113.   <span class="error">* <?php echo $emailErr;?></span> <br>
  114.   <br />
  115.  
  116.   <!-- These lines create a box for the user to input their password as well as space to display any required errors -->
  117.   Password:
  118.   <input type="text" name="password" id="password">
  119.   <span class="error">* <?php echo $passErr;?></span> <br>
  120.   <br />
  121.  
  122.   <!-- This line creates a button which, when clicked runs the PHP code above -->
  123.   <button type="submit" name="submit">Log in</button>
  124. </form>
  125. <br>
  126. <!-- This line produces a message depending on whether the login attempt has  succeeded or failed -->
  127. <p><?php echo $success;?></p>
  128. </body>
  129. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement