I have to execute 3 queries inside one PHP file. I have used mysqli_multi_query()
. The first 2 queries are SELECT queries which return values for third query (INSERT). So far I have done this;
<?php
$host = "localhost";
$user = "smartbusarrival_grouplog";
$password = "group10@10";
$db = "smartbusarrival_sbaDB";
$u_id = 51;
$b_id = 1;
$t_id = 1;
$date = '2017-06-30';
$startHalt = "Kaduwela";
$endHalt = "Nugegoda";
$seats = array(42,43);
$con = mysqli_connect($host,$user,$password,$db);
$query = "CALL getHaltTag('$t_id','$startHalt');";
$query .= "CALL getHaltTag('$t_id','$endHalt');";
$query .= "INSERT INTO reservation (user_id,bus_id,trip_id,date,start,end) values ('$u_id','$b_id','$t_id','$date','$startTag','$endTag')";
if(mysqli_multi_query($con, $query)){
do{
if($result = mysqli_store_result($con)){
while ($row = mysqli_fetch_array($result)){
$startTag = $row[0];
$endTag = $row[1];
}
mysqli_free_result($result);
}
}
while (mysqli_next_result($con));
}
mysqli_close($con);
?>
First two queries work very well and give correct answers. Code works just fine when inserting a new record. But the value of start and end are zero.