Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4. <form id = "login" method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>"/>
  5. <h3> Login </h3>
  6. Please enter your name:
  7. <input type = "text" size = "5" id = "username"/>
  8. <br />
  9. Please enter your password:
  10. <input type = "password" size = "5" id = "password"/>
  11. <input type ="submit" name = "submit" value = "Log in"/>
  12. <?php
  13. $conn = mysql_connect("localhost", "root", "") or die("cannot connect server ");
  14. mysql_select_db("nightsout") or die ("cannot find database");
  15.  
  16. if(isset($_POST['submit']))
  17. {
  18. $username = $_POST["username"];
  19. $password = $_POST["password"];
  20.  
  21. $username = stripslashes($username);//to protect from mysql injection
  22. $password = stripslashes($password);//to protect from mysql injection
  23. $username = mysql_real_escape_string($username);//to protect from mysql injection
  24. $password = mysql_real_escape_string($password);//to protect from mysql injection
  25.  
  26. $checklogin = ("select * from users WHERE username = '$username' && password = '$password'") or die('Cannot Execute:'. mysql_error());
  27. $result = mysql_query($checklogin);
  28. $rows = mysql_num_rows($result);
  29. if(mysql_num_rows($rows) != '0' && '1')
  30. {
  31. session_register("username");
  32. session_register("password");
  33. ?>
  34. <p> you have successfully logged in</p>
  35. <?php
  36. }else
  37. {
  38. ?>
  39. <p> Either your username or password was wrong or you are not registered, <a href="signup.php">click here</a> to register. </p>
  40. <?php
  41. }
  42. mysql_close($conn);
  43. }
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement