Guest User

Untitled

a guest
Mar 13th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <html>
  2. <body>
  3. <?php
  4.  
  5.  // connect to the mysql database
  6.  $con = new mysqli("127.0.0.1","root","seedubuntu","test_cms");
  7.  
  8.  // get the user data
  9.  $username = $_POST['user'];
  10.  $password = $_POST['password'];
  11.  
  12.  // query the database
  13.  $sql = "SELECT username FROM users WHERE username = ? AND password = ?";  
  14.  $stmt = $con->prepare($sql);
  15.  $stmt->bind_param("ss",$username,$password);
  16.  $stmt->execute();
  17.  $stmt->store_result();
  18.  $number_of_results = $stmt->num_rows;
  19.  
  20.  if ($number_of_results == 0)
  21.  {
  22.      print "Wrong username/password <br>";
  23.  }
  24.  else
  25.  {
  26.    $stmt->bind_result($name);
  27.        $stmt->fetch();
  28.    print "Welcome ".$name."! You are logged in.<br>";
  29.  }
  30.  // close the connection to the database
  31.  $stmt->close();
  32.  mysqli_close($con);
  33. ?>
  34. </body>
  35. </html>
Add Comment
Please, Sign In to add comment