Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
82
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 = "Hasło lub Login nie sa poprawne";
  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("baza", $connection);
  22. // SQL query to fetch information of registerd users and finds user match.
  23. $query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
  24. $rows = mysql_num_rows($query);
  25. if ($rows == 1) {
  26. $_SESSION['login_user']=$username; // Initializing Session
  27. header("location: profil.php"); // Redirecting To Other Page
  28. } else {
  29. $error = "Hasło lub Login nie sa poprawne";
  30. echo "blad";
  31. }
  32. mysql_close($connection); // Closing Connection
  33. }
  34. }
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement