Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 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. // To protect MySQL injection for Security purpose
  12. $username = stripslashes($username);
  13. $password = stripslashes($password);
  14. $username = mysqli_real_escape_string($username);
  15. $password = mysqli_real_escape_string($password);
  16. // Selecting Database
  17. $mysqli = new mysqli("localhost", "root", "root");
  18. $mysqli->select_db('tasty_recipe') or die ($mysqli->error);
  19. // SQL query to fetch information of registerd users and finds user match.
  20. $sql = $mysqli->query("SELECT * FROM `user` WHERE password='$password' AND username='$username'") or die ($mysqli->error);
  21. if ($sql->num_rows == 1) {
  22. $data = $sql->fetch_assoc();
  23. $_SESSION['username'] = $data['username']; // Initializing Session
  24. header("location: profile.php"); // Redirecting To Other Page
  25. } else {
  26. $error = "Username or Password is invalid";
  27. }
  28. mysqli_close($connection); // Closing Connection
  29. }
  30. }
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement