Advertisement
jqc21

Untitled

Apr 25th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2.  
  3. $host="localhost"; // Host name
  4. $username=**********; // Mysql username
  5. $password="*********"; // Mysql password
  6. $db_name="**********"; // Database name
  7. $tbl_name="users"; // Table name
  8.  
  9. // Connect to server and select databse.
  10. mysql_connect ($host, $username, $password)or die("cannot connect to server");
  11. mysql_select_db("$db_name")or die("cannot select DB");if(mysql_errno()) { echo ' Error '.mysql_errno().' '.mysql_error().'<br>'; }
  12.  
  13. // username and password sent from form
  14. $myusername=$_POST['myusername'];
  15. $mypassword=$_POST['mypassword'];
  16. if($myusername<>'') {
  17. // To protect MySQL injection (more detail about MySQL injection)
  18. $myusername = stripslashes($myusername);
  19. $mypassword = stripslashes($mypassword);
  20. $myusername = mysql_real_escape_string($myusername);
  21. $mypassword = mysql_real_escape_string($mypassword);
  22. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  23.  
  24.  
  25. // Mysqli_num_row is counting table row
  26. $count=mysql_num_rows($result);
  27.  
  28. // If result matched $myusername and $mypassword, table row must be 0 row
  29. if($count==1){
  30.  
  31. // Register $myusername, $mypassword and redirect to file "login_success.php"
  32. session_register("myusername");
  33. session_register("mypassword");
  34. header("location:login_success.php");
  35. }
  36. } else {
  37. if($_POST['submit']<>'') #submit button like: <input type="submit" name="submit" value="Submit" >
  38. {
  39. #empty submit
  40. echo 'Please fill all the fields';
  41. } else {
  42. #no submit yet.
  43. echo 'Please submit the form.';
  44. #link to the form.
  45. }
  46. }
  47. echo "Wrong Username or Password";
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement