Guest User

Untitled

a guest
Sep 26th, 2017
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2. if($_SERVER["REQUEST_METHOD"] == "POST"){
  3. $username = $_POST['username'];
  4. $password = $_POST['password'];
  5. $bool = true;
  6. //open connection to db
  7. $con = @mysqli_connect('localhost', 'root', '');
  8. if (!$con){
  9. echo "Error: " .mysqli_connect_error();
  10. exit();
  11. }
  12. $sql = 'SELECT * FROM users';
  13. $query = mysqli_query($con, $sql);
  14. whiile ($row = mysqli_fetch_array($query)){
  15. $table_users = $row['username'];
  16. if ($username == $table_users){
  17. $bool = false;
  18. Print '<script>alert("username has been taken!");</script>';
  19. Print '<script>window.location.assign("register.php");</script>';
  20. }
  21. }
  22. if ($bool){
  23. mysqli_query("INSERT INTO users (username, password) VALUES ('$username','$password')");
  24. Print '<script>alert("Successfully Registered");</script>';
  25. Print '<script>window.location.assign("register.php");</script>';
  26. }
  27. }
  28. //Closes connection
  29. mysqli_close ($con);
  30. ?>
Add Comment
Please, Sign In to add comment