Advertisement
Guest User

Untitled

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