Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Connect to server and select database.
- $conn = mysqli_connect("localhost", "root", "", "csdvideoapp") or die("Connection Server" . mysqli_error());
- // $selet = mysqli_select_db("first_db", "root", "") or die("Cannot connect to database");
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- $username = $_POST['Username'];
- $email = $_POST['Email'];
- $employee = $_POST['EmployeeID'];
- $designation = $_POST['Designation'];
- $password = $_POST['Password'];
- $bool = true;
- $query = mysqli_query($conn, "Select * from users"); //Query for the users table
- while($row = mysqli_fetch_array($query)) //display all rows from table users
- {
- $table_users = $row['Username'];
- if($username == $table_users) //checks if there are matching fields
- {
- $bool = false;
- Print '<script>alert("Username has been taken!");</script>'; //Prompts the user
- Print '<script>window.location.assign("index.html");</script>'; //redirecting to register.php
- }
- }
- if($bool) //checks if $bool is 'true'
- {
- mysqli_query($conn, "INSERT INTO users (Username, Email, EmployeeID, Designation, Password) VALUES ('$username','$email','$employee','$designation','$password')"); // inserts the values to table users
- Print '<script>alert("Successfully Registered!");</script>'; //Prompts the user
- Print '<script>window.location.assign("index.html");</script>'; //redirecting to register.php
- }
- }
- ?>
Add Comment
Please, Sign In to add comment