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

	$act=$_GET['act'];

	switch ($act){
		case 'chk_username':
			$username = mysqli_real_escape_string($conn,$_GET["username"]);
			chk_username($username);
			break;
		case 'chk_email':
			$email = mysqli_real_escape_string($conn,$_GET["email"]);
			chk_email($email);
			break;
	}


	function chk_username($username){
		include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

			$result = $conn->query("SELECT * FROM user_account");
			$username_existed = false;
				
				if($result) {
					while ( $row = $result->fetch_assoc() ){
						
						// echo 'no code is found';
						if ($row['username'] == $username){
							$username_existed = true;

							echo 1;
						}
						
					}
				}

		$conn->close();
	}

	function chk_email($email){
		include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

			$result = $conn->query("SELECT * FROM user_account");
			$email_existed = false;

				if($result) {
					while ( $row = $result->fetch_assoc() ){
						
						// echo 'no code is found';
						if ($row['email'] == $email){
							$email_existed = true;
							echo 1;
						}
						
					}
				}

		$conn->close();
	}


	// $code=$_GET['code'];
	// // echo "no code is found";

	// $result = $conn->query("SELECT * FROM user_account");
		
	// 	if($result) {
	// 		while ( $row = $result->fetch_assoc() ){
				
	// 			// echo 'no code is found';
	// 			if ($row['specific_classCode'] == $code){
	// 				echo "<span>Student</span>";
	// 				echo "<br>";
	// 				echo "<span>class: ".$row['class_name']."</span>";
	// 			}
	// 			else if ($row['specific_teacherCode'] == $code){
	// 				echo "<span>Teacher</span>";
	// 			}
	// 			else if ($row['specific_staffCode'] == $code){
	// 				echo "<span>School-IT-Admin</span>";
	// 			}
	// 			else{
	// 				echo "<span>the code is invalid</span>";
	// 			}
				
	// 		}
	// 	}

	// $conn->close();
?>