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

	$newName = $_GET["newName"];
	$new_sCode = $_GET["new_sCode"];
	$new_tCode = '';

		// generate 'id'
		$id_set = false;

		$result = $conn->query("SELECT * FROM school");
			if($result) {
				$id = 1;
				while ( $row = $result->fetch_assoc() ){
					
					if ($id == $row['school_id'] && $id_set == false){  //if 'id' already exist, increment
						$id++;
					}
					else if ($id < $row['school_id']){  //no more increment
						$id_set = true;
					}
				}
			}


		if ($conn->query("INSERT INTO school VALUES ('$id', '$newName', '$new_sCode', '$new_tCode')") === TRUE) {
			echo 'done';
			
		}
	
   $conn->close();
?>