Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
151
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. }
  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. $servername = "localhost";
  15. $username = "root";
  16. $password = "";
  17. $dbname = "server1";
  18. // Create connection
  19. $conn = new mysqli($servername, $username, $password,$dbname);
  20.  
  21. // Check connection
  22. if ($conn->connect_error) {
  23. die("Connection failed: " . $conn->connect_error);
  24. }
  25. // To protect mysqli injection for Security purpose
  26. $username = stripslashes($username);
  27. $password = stripslashes($password);
  28. $username = mysqli_real_escape_string($username);
  29. $password = mysqli_real_escape_string($password);
  30. // Selecting Database
  31. $db = mysqli_select_db("server1", $conn);
  32. // SQL query to fetch information of registerd users and finds user match.
  33. $query = "select * from account where password='$password' AND username='$username'";
  34. $result = mysqli_query($conn, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($mysqli), E_USER_ERROR);;
  35. $rows = mysqli_num_rows($query);
  36. if ($rows == 1) {
  37. $_SESSION['login_user']=$username; // Initializing Session
  38. header("location: profile.php"); // Redirecting To Other Page
  39. } else {
  40. $error = "Username or Password is invalid";
  41. }
  42. mysqli_close($conn); // Closing Connection
  43. }
  44. }
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement