Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2. $host="localhost"; // Host name
  3. $username="root"; // Mysql username
  4. $password=""; // Mysql password
  5. $db_name="test2"; // Database name
  6. $tbl_name="members"; // Table name
  7. // Connect to server and select databse.
  8. $link = mysqli_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysqli_select_db("$db_name")or die("cannot select DB");
  10.  
  11. // username and password sent from form
  12. $myusername=$_POST['myusername'];
  13. $mypassword=$_POST['mypassword'];
  14.  
  15. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  16. $result=mysqli_query($sql);
  17.  
  18. // Mysql_num_row is counting table row
  19. $count=mysqli_num_rows($result);
  20.  
  21. // If result matched $myusername and $mypassword, table row must be 1 row
  22. if($count==1){
  23.  
  24. // Register $myusername, $mypassword and redirect to file "login_success.php"
  25.      header("location:login_success.php");
  26. }
  27. else {
  28. echo "Wrong Username or Password";
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement