Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <?php
  2. if($_SERVER["REQUEST_METHOD"] == "POST"){
  3. $username = mysql_real_escape_string($_POST['username']);
  4. $password = mysql_real_escape_string($_POST['password']);
  5. $email = mysql_real_escape_string($_POST['email']);
  6. $fname = mysql_real_escape_string($_POST['fname']);
  7. $lname = mysql_real_escape_string($_POST['lname']);
  8. $bool = true;
  9. mysql_connect("localhost", "root","rot_darshan") or die("Cannot connect to server"); //Connect to server
  10. mysql_select_db("first_db") or die("Cannot connect to database"); //Connect to database
  11. $query = mysql_query("Select * from users"); //Query the users table
  12. while($row = mysql_fetch_array($query)) //display all rows from query
  13. {
  14. $table_users = $row['username']; // the first username row is passed on to $table_users, and so on until the query is finished
  15. if($username == $table_users) // checks if there are any matching fields
  16. {
  17. $bool = false; // sets bool to false
  18. Print '<script>alert("Username has been taken!");</script>'; //Prompts the user
  19. Print '<script>window.location.assign("register.php");</script>'; // redirects to register.php
  20. }
  21. }
  22. if($bool) // checks if bool is true
  23. {
  24. mysql_query("INSERT INTO users (username, password,fname,lname,email) VALUES ('$username','$password','$fname','$lname','$email')"); //Inserts the value to table users
  25. Print '<script>alert("Successfully Registered!");</script>'; // Prompts the user
  26. Print '<script>window.location.assign("register.php");</script>'; // redirects to register.php
  27. }
  28. }
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement