<?php
	include_once("db.php");

	//make result object
	$result = array();
	$result['ok'] = false;

	//get post data
	$postdata = file_get_contents("php://input");
	$post = json_decode($postdata, true);

	$idchampionship = $post['idchampionship'];
	$idteam = $post['idteam'];
	$drivername = $post['name'];

	$adddriver= pg_prepare($dbconn, "adddriver", "insert into driver (name, idchampionship, idteam) values ($1, $2, $3) returning iddriver");
	$adddriver= pg_execute($dbconn, "adddriver", array($drivername, $idchampionship, $idteam));

	if($adddriver===FALSE) {
		$result['ok'] = false;
		$result['error'] = 'insert driver failed: '.pg_last_error($dbconn);
	// 	$result['debug1'] = "insert into driver (name, idchampionship, idteam) values ($1, $2, $3) returning iddriver";
	// 	$result['debug2'] = $;
	} else {
		$result['ok'] = true;
	}

	//print message
	$resultjson =  json_encode($result);

	echo $resultjson;
?>
