<?php


if($_SERVER["REQUEST_METHOD"]=="POST"){

    createStudent();
}
function createStudent()
{

    //global $connect;

    $servername = "localhost";
    $username = "dotrazie_android";
    $password = "12345!@#$%";
    $dbname = "dotrazie_android";

// Create connection
    $conn = new mysqli($servername, $username, $password,$dbname);

    $idClient = $_POST["idClient"];
    $idCafea = $_POST["idCafea"];
    $checkSoya = $_POST["checkSoya"];
    $checkShot = $_POST["checkExtraShot"];
    $variatie = $_POST["variatie"];
    $nivelLapte = $_POST["nivelLapte"];
    $nivelSpuma = $_POST["nivelSpuma"];
    $total = $_POST["total"];
    $latitude = $_POST["latitude"];
    $longitutde = $_POST["longi"];
    $estimatedTime = $_POST["estimatedTime"];
    $phoneStored = $_POST["phoneStored"];

    //$age = $_POST["age"];

    //$queryInsert = "Insert into tblComenzi(IDCafea,IDClient,Variatie,LapteSoya,ExtraShot,NivelLapte,NivelSpuma,Latitude,Longitude,Estimation,Total) values (1,2,'test','true','true',50,10,12.123123,12.121212,'10 min',10)";

    $queryInsert = "Insert into tblComenzi(IDCafea,IDClient,DataAdd,OraAdd,Telefon,Variatie,LapteSoya,ExtraShot,NivelLapte,NivelSpuma,Latitude,Longitude,Estimation,Total) values ($idCafea,(SELECT ID from tblUtilizatori WHERE Telefon = '$phoneStored'),NOW(),NOW(),'$phoneStored','$variatie','$checkSoya','$checkShot',$nivelLapte,$nivelSpuma,$latitude,$longitutde,'$estimatedTime',$total);";

    //mysqli_query($conn, $query) or die (mysqli_error($conn));

    if (mysqli_query($conn, $queryInsert) or die (mysqli_error($conn) . "\nquery:" . $queryInsert));




    $query = "SELECT ID, Status FROM `tblComenzi` WHERE Telefon = '$phoneStored' ORDER BY ID DESC LIMIT 1";

    $result = mysqli_query($conn,$query);

    //$response = array();
    $row = mysqli_fetch_array($result);



    if (mysqli_query($conn, $query) or die (mysqli_error($conn) . "\nquery:" . $query)) echo $row[0];

    mysqli_close($conn);

}
?>