Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2.     session_start(); // Starting Session
  3.     $error=''; // Variable To Store Error Message
  4.  
  5.  
  6.     if (isset($_POST["hantar"]))
  7.     {
  8.         if (empty($_POST["username"]) || empty($_POST["password"])) {
  9.             $error = "Username or Password is invaaaalid";
  10.     }
  11.  
  12.     else
  13.     {
  14.     // Define $username and $password
  15.     $username=$_POST['username'];
  16.     $password=$_POST['password'];
  17.     // Establishing Connection with Server by passing server_name, user_id and password as a parameter
  18.     $connection = mysql_connect("localhost", "root", "admin1234");
  19.     // To protect MySQL injection for Security purpose
  20.     $username = stripslashes($username);
  21.     $password = stripslashes($password);
  22.     $username = mysql_real_escape_string($username);
  23.     $password = mysql_real_escape_string($password);
  24.     // Selecting Database
  25.     $db = mysql_select_db("molexdb", $connection);
  26.     // SQL query to fetch information of registerd users and finds user match.
  27.     $query = mysql_query("select * from client where client_pass='$password' AND client_id='$username'", $connection);
  28.     $rows = mysql_num_rows($query);
  29.     if (!$query) {
  30.     die(mysql_error());
  31. }
  32.     if ($rows == 1) {
  33.     $_SESSION['login_user']=$username; // Initializing Session
  34.     header("location: client-home.php"); // Redirecting To Other Page
  35.     } else {
  36.     $error = "Username or Password is invalid .";
  37.     }
  38.     mysql_close($connection); // Closing Connection
  39.     }
  40.     }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement