shabbyheart

PHP first Class db connect

Nov 4th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 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 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.  
  22.  
  23.  
  24.  
  25. dbconn.php
  26.  
  27. <?php
  28. $con = mysqli_connect("localhost","root","","crud");
  29. if (mysqli_connect_errno())
  30.   {
  31.   echo "Failed to connect to MySQL: " . mysqli_connect_error();
  32.   }
  33. else
  34.   {
  35.     //echo "Database Connection Successfull";
  36.   }
  37. ?>
  38.  
  39.  
  40.  
  41. regProcess.php
  42.  
  43. <html>
  44. <head>
  45.     <title>Login</title>
  46. </head>
  47. <body>
  48.         <h2>Register</h2>
  49.     <form method="post" action="regProcess.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.  
  61. login.php
  62.  
  63. <html>
  64. <head>
  65.     <title>Login</title>
  66. </head>
  67. <body>
  68.         <h2>Register</h2>
  69.     <form method="post" action="loginProcess.php">
  70.             <label>Username</label>
  71.             <input type="text" name="username">
  72.             <label>Password</label>
  73.             <input type="password" name="password">
  74.             <button type="submit" class="btn" name="login_btn">Login</button>
  75.     </form>
  76. </body>
  77. </html>
  78.  
  79.  
  80.  
  81. loginProcess.php
  82.  
  83. <?php
  84.         require('dbconn.php');
  85.         if (isset($_POST['login_btn'])){
  86.         $username    = $_POST['username'];
  87.         $password = $_POST['password'];
  88.        
  89.         $query = "SELECT * FROM user WHERE username='$username' AND password='$password'";
  90.         $results = mysqli_query($con, $query);
  91.  
  92.         if (mysqli_num_rows($results) == 1) {
  93.         echo "$username Login Successfully";
  94.         }
  95.         else
  96.         {
  97.             echo "Login faild";
  98.         }
  99.     }
  100. ?>
Add Comment
Please, Sign In to add comment