Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php include '../config.php'; ?>
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>Register</title>
  6. </head>
  7. <body>
  8. <form action="register.php" method="POST">
  9. <input type="text" placeholder="Username..." name="username"><br><br>
  10. <input type="text" placeholder="Email..." name="email"><br><br>
  11. <input type="password" placeholder="Password..." name="password"><br><br>
  12. <input type="password" placeholder="Repeat password..." name="password2"><br><br>
  13. <button type="submit" name="submit">Register</button>
  14. </form>
  15. </body>
  16. </html>
  17.  
  18. <?php
  19.  
  20.  
  21. if (isset($_POST['submit'])) {
  22.  
  23.  
  24. $username = $_POST['username'];
  25. $email = $_POST['email'];
  26. $password = $_POST['password'];
  27.  
  28. $errors = array();
  29.  
  30. if (trim($_POST['username']) == '') {
  31. $errors[] = 'Empty username!';
  32. }
  33. if (trim($_POST['email']) == '') {
  34. $errors[] = 'Empty email';
  35. }
  36. if ($_POST['password'] == '') {
  37. $errors[] = 'Please enter password!';
  38. }
  39. if ($_POST['password2'] !== $_POST['password']) {
  40. $errors[] = 'Passwords do not match!';
  41. }
  42. if (empty($errors)) {
  43. mysqli_query($db_connect, "INSERT INTO registration (user_name,email) VALUES ('$username', '$email')");
  44.  
  45.  
  46. } else {
  47. echo 'OoOops '.array_shift($errors). '' ;
  48. }
  49. }
  50. // if (!$db_connect) {
  51. // echo 'No connection to database!';
  52. // } else {
  53. // echo 'All OK, we are connected to DB!';
  54. // }
  55. mysqli_close($db_connect);
  56. ?>
  57.  
  58. <?php
  59.  
  60. // define - Defines A Named Constant
  61. $conn_error = 'Could not connect!';
  62.  
  63. define("DB_SERVER", "localhost");
  64. define("DB_USERNAME", "root");
  65. define("DB_PASSWORD", "");
  66. define("DB_DATABASE", "test");
  67.  
  68. // We Connect To database
  69. // Ar @ Zimi Neparadisies Errors
  70. $db_connect = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE) or die ("$conn_error");
  71.  
  72. // $db_select = mysqli_select_db(DB_DATABASE);
  73.  
  74. if (!$db_connect) {
  75. die ("$conn_error");
  76. }
  77. // } else {
  78. // echo "All OK!"; // If It's Connected will dispaly All OK!
  79. // }
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement