Advertisement
Guest User

Untitled

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