Advertisement
pgeeweb

7.12.2016 - register.php

Dec 7th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. <?php
  2. $con = mysqli_connect("localhost","root","","vaflichka2");
  3.  
  4. // Check connection
  5. $errno = mysqli_connect_errno();
  6.  
  7. if ($errno) {
  8.     echo "Failed to connect to MySQL: " . mysqli_connect_error();
  9.     die();
  10. }
  11.  
  12. /*$query = mysqli_query($con, "SELECT username, email FROM users WHERE id=3");
  13.  
  14. while($row = mysqli_fetch_assoc($query)) {
  15.     print_r($row);
  16.     echo "<br>**************************<br>";
  17. }*/
  18.  
  19.  
  20. if(isset($_POST["username"])) {
  21.     $username = $_POST["username"];
  22. } else {
  23.     die("Hacking attempt detected. Nice try!");
  24. }
  25.  
  26. if(isset($_POST["password"])) {
  27.     $password = $_POST["password"];
  28. } else {
  29.     die("Hacking attempt detected. Nice try!");
  30. }
  31.  
  32. if(isset($_POST["confirm_password"])) {
  33.     $confirm_password = $_POST["confirm_password"];
  34. } else {
  35.     die("Hacking attempt detected. Nice try!");
  36. }
  37.  
  38. if(isset($_POST["email"])) {
  39.     $email = $_POST["email"];  
  40. } else {
  41.     die("Hacking attempt detected. Nice try!");
  42. }
  43.  
  44. if(isset($_POST["name"])) {
  45.     $name = $_POST["name"];
  46. } else {
  47.     die("Hacking attempt detected. Nice try!");
  48. }
  49.  
  50.  
  51. $errors = array();
  52. if(!(strlen($username)>=3 && strlen($username)<=30)) {
  53.     $errors[] = "Error: The username should be between 3 and 30 characters.";
  54. }
  55.  
  56. if(!(strlen($password)>=6 && strlen($password)<=30)) {
  57.     $errors[] = "Error: The password should be between 6 and 30 characters.";
  58. }
  59.  
  60. if($password!=$confirm_password) {
  61.     $errors[] = "Error: The passwords do not match!";
  62. }
  63.  
  64. $query = mysqli_query($con, "SELECT * FROM users WHERE username='".$username."'");
  65. $userCount = mysqli_num_rows($query);
  66.  
  67.  
  68. if($userCount>0) {
  69.     $errors[] = "Error: The username is already taken!";
  70. }
  71.  
  72. if(count($errors)>0) {
  73.     foreach($errors as $error) {
  74.         echo $error."<br>";
  75.     }
  76. } else {
  77.     echo "You've registered successfully.";
  78.     $query = mysqli_query($con, "INSERT INTO users (username, password, email, name) VALUES ('".$username."', '".$password."', '".$email."', '".$name."')");
  79. }
  80.  
  81.  
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement