if (isset($_POST['finalSeats']))
{
getting variable from post
$TicketType =$_POST['Tickettype'];
$seatS=$_POST['finalSeats'];
$EventId=$_POST["Eventid"];
array getting from last page
$cats = array_filter(array_map('trim', explode(',', $seatS)));
$sqlData = array();
getting values one by one with foreach
foreach($cats as $key => $cat ) {
$stmt = $con->prepare("SELECT * FROM fistevent WHERE `Event_Id`=? AND `TicketType`=? AND `seats`= ?") or die($con->error);
$stmt->bind_param("sss",$EventId , $TicketType,$cat);
$stmt->execute();
$stmt->store_result();
Bind the results
$stmt-> bind_result($id,$Event_Id,$TicketType,$row_name,$seats,$Status);
while($stmt->fetch())
{
$data[] = array($id,$Event_Id,$TicketType,$row_name,$seats,$Status);
$Tickettype=$TicketType;
$Rowname=$row_name;
$Seats=$seats;
$status=$Status;
Comparing values array and database values
if($Seats===$cat && $status==='Hold')
{
echo'<script>window.location="selection.php";</script>';
}
if not matched update the query
else
{
$seatS=$_POST['finalSeats'];
$Eventid=$_POST["Eventid"];
$_SESSION['Eventid']=$Eventid;
$cats = array_filter(array_map('trim', explode(',', $seatS)));
$stmt = $con->prepare('UPDATE fistevent SET `Status`="Hold" where `Event_Id`=? AND `seats`= ? ') or die($con->error);
$stmt->bind_param("ss", $_POST['Eventid'], $cat);
foreach($cats as $key => $cat ) {
$stmt->execute();
}
}
}
}
}