Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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 = mysql_connect("localhost", "root", "root");
  13. // To protect MySQL injection for Security purpose
  14. $username = stripslashes($username);
  15. $password = stripslashes($password);
  16. $username = mysql_real_escape_string($username);
  17. $password = mysql_real_escape_string($password);
  18. // Selecting Database
  19. $db = mysql_select_db("tasty_recipe", $connection);
  20. // SQL query to fetch information of registerd users and finds user match.
  21. $query = mysql_query("SELECT * FROM 'user' WHERE password='$password' AND username='$username'", $connection);
  22. $rows = mysql_num_rows($query);
  23. if ($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. mysql_close($connection); // Closing Connection
  30. }
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement