Advertisement
Guest User

james

a guest
Jul 22nd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. $servername="localhost";
  4. $username="root";
  5. $password="";
  6.  
  7. $conn = new mysqli($servername,$username,$password) or die ("Cant connect to database");
  8. mysqli_select_db($conn,"db_login");
  9.  
  10.  
  11. if(mysqli_connect_errno()){
  12. echo 'failed to connect to database<br>';
  13. }
  14. else{
  15. echo "connected<br>";
  16. }
  17.  
  18. if(isset($_POST['login'])){
  19. $user=$_POST['username'];
  20. $pass=$_POST["password"];
  21.  
  22. $query="SELECT * FROM 'admin' WHERE username='$user' and password='$pass'";
  23.  
  24. if($result=mysqli_query($conn,$query)){
  25. $rowcount = mysql_num_rows($result);
  26. if(rowcount>=1){
  27. header('location:index.php');
  28. }
  29. else{
  30. echo "login failed";
  31. }
  32. }
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. ?>
  41. <!DOCTYPE html>
  42. <html>
  43. <head>
  44. <title> Login </title>
  45. </head>
  46. <form method="post">
  47. <body>
  48.  
  49. <input type="text" name="username" placeholder="username"><br>
  50. <input type="password" name="password" placeholder="password"><br>
  51. <input type="submit" name="login">
  52.  
  53.  
  54. </body>
  55. </form>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement