Advertisement
Guest User

Untitled

a guest
Jan 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. session_start(); // Starting Session
  4. $error=''; // Variable To Store Error Message
  5. if (isset($_POST['submit'])) {
  6. if (empty($_POST['username']) || empty($_POST['password'])) {
  7. $error = "Username or Password is invalid";
  8. }
  9. else
  10. {
  11. // Define $username and $password
  12. $username=$_POST['username'];
  13. $password=$_POST['password'];
  14. // Establishing Connection with Server by passing server_name, user_id and password as a parameter
  15. $connection = mysqli_connect('localhost','root','','zedb');
  16. // To protect MySQL injection for Security purpose
  17.  
  18.  
  19.  
  20. // SQL query to fetch information of registerd users and finds user match.
  21. $query = mysqli_query($connection, "SELECT * FROM tbluser WHERE Username = \"".$_POST["username"]."\" AND Password = \"".$_POST["password"]."\";");
  22. $rows = mysqli_num_rows($query);
  23. if ($rows == 1) {
  24. $_SESSION['login_user']= $username; // Initializing Session
  25. header("location: indexLogIn.php"); // Redirecting To Other Page
  26. } else {
  27. $error = "Username or Password is invalid";
  28. }
  29. mysqli_close($connection); // Closing Connection
  30. }
  31. }
  32.  
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement