<?php
	include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

    //THis page has been created to validate if a certain username already exists!!
	$username = $_POST["user"];
	// echo "no code is found";

    $username_exists = false;

	$result = $conn->query("SELECT * FROM user_account");
		
		if($result) {
			while ( $row = $result->fetch_assoc() ){
                
                if($row["username"] == $username){
                    $username_exists = true;
                    echo "Username is already taken!";
                }else{
                    //User name is not taken so far
                    $username_exists = false;
                }
				
			}
        }
        
        if(!$username_exists){
            echo "Username is Unique!";
        }

	$conn->close();
?>