Advertisement
Tarikul_Islam

1.PHP for Database Connection

Nov 10th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. registration.php
  2.  
  3. <html>
  4. <head>
  5. <title>Registration</title>
  6. </head>
  7. <body>
  8. <h2>Register</h2>
  9. <form method="post" action="regProcess.php">
  10. <label>Username</label>
  11. <input required ="required"type="text" name="username">
  12. <label>Email</label>
  13. <input type="email" name="email">
  14. <label>Password</label>
  15. <input type="password" name="password">
  16. <button type="submit" class="btn" name="register_btn">Register</button>
  17. </form>
  18. </body>
  19. </html>
  20.  
  21. regprocess.php
  22.  
  23. <?php
  24. require('dbconn.php');
  25. if (isset($_POST['register_btn'])){
  26. $username = $_POST['username'];
  27. $email = $_POST['email'];
  28. $password = $_POST['password'];
  29. $query = "INSERT into `user` (Username, Email, Password) VALUES ('$username', '$email', '$password')";
  30. $result = mysqli_query($con,$query);
  31. if($result){
  32. echo "You are registered successfully.";
  33. }
  34. }else{
  35. echo "Faild.";
  36. }
  37. ?>
  38.  
  39.  
  40. login.php
  41.  
  42.  
  43. <html>
  44. <head>
  45. <title>Login</title>
  46. </head>
  47. <body>
  48. <h2>Register</h2>
  49. <form method="post" action="loginProcess.php">
  50. <label>Username</label>
  51. <input type="text" name="username">
  52. <label>Password</label>
  53. <input type="password" name="password">
  54. <button type="submit" class="btn" name="login_btn">Login</button>
  55. </form>
  56. </body>
  57. </html>
  58.  
  59.  
  60. loginprocess.php
  61.  
  62.  
  63. <?php
  64. require('dbconn.php');
  65. if (isset($_POST['login_btn'])){
  66. $username = $_POST['username'];
  67. $password = $_POST['password'];
  68.  
  69. $query = "SELECT * FROM user WHERE username='$username' AND password='$password'";
  70. $results = mysqli_query($con, $query);
  71.  
  72. if (mysqli_num_rows($results) == 1) {
  73. echo "$username Login Successfully";
  74. }
  75. else
  76. {
  77. echo "Login faild";
  78. }
  79. }
  80. ?>
  81.  
  82.  
  83.  
  84. dbconn.php
  85.  
  86.  
  87. <?php
  88. $con = mysqli_connect("localhost","root","","user");
  89. if (mysqli_connect_errno())
  90. {
  91. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  92. }
  93. else
  94. {
  95. echo "Database Connection Successfull";
  96. }
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement