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

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

		// generate 'id'
		$result = $conn->query("SELECT * FROM survey");
			if($result) {
				$id = 1;
				while ( $row = $result->fetch_assoc() ){
					
					if ($id <= $row['survey_id']){  //if 'id' already exist, increment
						$id = $row['survey_id'] +1;
					}
				}
			}

		// generate 'Order-id'
		$result = $conn->query("SELECT * FROM survey");
			if($result) {
				$id_order = 1;
				while ( $row = $result->fetch_assoc() ){
					
					if ($id_order <= $row['order_id']){  //if 'id' already exist, increment
						$id_order = $row['order_id'] +1;
					}
				}
			}


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