Advertisement
Guest User

Untitled

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