<?php
$link = mysqli_connect("127.0.0.1", "alumne", "keiL2lai", "jbalmes");
$nom = $_REQUEST['nom'];
$taula = $_REQUEST['taula'];
$plats = $_REQUEST['plats'];
//funció split:
//This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. 
$plats = explode(';', $plats);

//echo $nom;
//echo $taula;
//echo $plats[0];

$sql = "select max(id_client) as max_id_client from client";
$result = mysqli_query($link,$sql);
$row = mysqli_fetch_assoc($result);
if (!isset($row['max_id_client'])){
	$vid_client=1;
} else {
	$vid_client=$row['max_id_client']+1;
}

$sentencia = "INSERT INTO client (id_client, nom, taula) VALUES (".$vid_client.",'".$nom."', '".$taula."');";
echo $sentencia;
mysqli_query($link, $sentencia);


$string = "Hola ".$nom.", has reservat la taula ".$taula." amb els següents plats:<br>";
echo $string;
for($i = 0; $i<sizeof($plats)-1;$i++){
	$sentencia = "INSERT INTO plat (id_client, nom_plat) VALUES (".$vid_client.", '".$plats[$i]."');";
	echo $sentencia."<br />";
	mysqli_query($link, $sentencia);
	echo $plats[$i]."<br />";
	$err=mysqli_error($link);
	print"$err";
	
}

//$sentencia = "INSERT INTO test.plats "

?>
