Guest User

Untitled

a guest
Apr 6th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <?php
  2. // Connect to server and select database.
  3. $conn = mysqli_connect("localhost", "root", "", "csdvideoapp") or die("Connection Server" . mysqli_error());
  4. // $selet = mysqli_select_db("first_db", "root", "") or die("Cannot connect to database");
  5.  
  6. if($_SERVER["REQUEST_METHOD"] == "POST"){
  7. $username = $_POST['Username'];
  8. $email = $_POST['Email'];
  9. $employee = $_POST['EmployeeID'];
  10. $designation = $_POST['Designation'];
  11. $password = $_POST['Password'];
  12. $bool = true;
  13. $query = mysqli_query($conn, "Select * from users"); //Query for the users table
  14. while($row = mysqli_fetch_array($query)) //display all rows from table users
  15. {
  16. $table_users = $row['Username'];
  17. if($username == $table_users) //checks if there are matching fields
  18. {
  19. $bool = false;
  20. Print '<script>alert("Username has been taken!");</script>'; //Prompts the user
  21. Print '<script>window.location.assign("index.html");</script>'; //redirecting to register.php
  22. }
  23. }
  24.  
  25. if($bool) //checks if $bool is 'true'
  26. {
  27. mysqli_query($conn, "INSERT INTO users (Username, Email, EmployeeID, Designation, Password) VALUES ('$username','$email','$employee','$designation','$password')"); // inserts the values to table users
  28. Print '<script>alert("Successfully Registered!");</script>'; //Prompts the user
  29. Print '<script>window.location.assign("index.html");</script>'; //redirecting to register.php
  30. }
  31.  
  32. }
  33. ?>
Add Comment
Please, Sign In to add comment