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

	$newName = $_GET["newName"];
	$newUrl = $_GET["newUrl"];
	$newOrder = $_GET["newOrder"] +1;

		// generate 'id'
		$id_set = false;

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


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