Advertisement
michaelyuen

Untitled

Feb 26th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2. $con = mysqli_connect('localhost','root','','polo');
  3.  
  4. function login($email,$pass) {
  5.     // function cannot access variable that is out of function scope, so you would need to use global
  6.     global $con;
  7.     $email = mysqli_real_escape_string($con,$email);
  8.     $pass = mysqli_real_escape_string($con,$pass);
  9.     $query = "SELECT * FROM customer WHERE email='".$email."' AND password='".$pass."'";
  10.     // connection failure
  11.     if (!$result = mysqli_query($con,$query)) {
  12.         echo 'Error :' . mysqli_error($con);
  13.         return false;
  14.     }
  15.     // no matching record
  16.     if (mysqli_num_rows($result) == 0) {
  17.         echo 'Warning: Invalid Login';
  18.         return false;
  19.     }
  20.     return true;
  21. }
  22.  
  23. if (ISSET($_POST['login'])) {
  24.     $email=$_POST['email'];
  25.     $pass=$_POST['pass'];
  26.     if (login($email,$pass)) {
  27.         echo 'Login Successful';
  28.     }
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement