I always get this error whenever I submit ”
Warning: Undefined array key “seats” in C:xampphtdocsLaCineReservabooking.php on line 30Warning: foreach() argument must be of type array|object, null given in C:xampphtdocsLaCineReservabooking.php on line 34
” I don’t know why it always say null even if I checked some boxes.
This is the code I’ve used for this.
if(isset($_POST["btn_booking"]))
{
// include("checkSeat.php");
$con=new connec();
$cust_id=$_POST["cust_id"];
$show_id=$_POST["show_id"];
$no_tikt=$_POST["no_ticket"];
$bkng_date=$_POST["booking_date"];
$total_amnt=(600 * $no_tikt);
$bookedSeats = $_POST['seats'];
$data = array();
foreach($bookedSeats as $seat)
$data[] = addslashes($seat);
$data = implode("," , $data);
$sql="insert into seat_reserved values(0,$show_id,$cust_id,'$data','true')";
$abc= $con->insert_lastid($sql);
$sql="insert into seat_detail values(0,$cust_id,$show_id,$no_tikt)";
$seat_dt_id=$con->insert_lastid($sql);
$sql="insert into booking values(0,$cust_id,$show_id,$no_tikt,$seat_dt_id,'$bkng_date',$total_amnt)";
$con->insert($sql,"Your Ticket is Booked");
}
<div class="row">
<form method="POST">
<table style="width:100%;color:white;">
<tr>
<td>A</td>
<td><input type="checkbox" name="seats[]" value="A-01" onclick="checkboxtotal()" <?php checkme("A-01",$ajaycomma); ?>></td>
<td><input type="checkbox" name="seats[]" value="A-02" onclick="checkboxtotal()" <?php checkme("A-02",$ajaycomma); ?>></td>
<td><input type="checkbox" name="seats[]" value="A-03" onclick="checkboxtotal()" <?php checkme("A-03",$ajaycomma); ?>></td>
</tr>
</table>
</form>
</div>