mardi 27 novembre 2018

how to use checkbox and input type number together in php

I am creating a meeting room booking application using php. In that, when a person book a room there have an option to book tea or snacks and specify the number of items they need. For that, I use checkboxes to select items and input type number to specify the number of items.i.e, if tea selected you have to specify the no. of tea in the input field. My problem is that I can't store or display the checkbox value and associated number together.my code is

<form class="form-horizontal" method="post" id="bookroom" action="bookedreview.php">
<h4>Food & Beverages</h4>
<div class="checkbox">
 <input type="checkbox" value="tea" name="food[]"><label>Tea</label>
 <input type="number" name="foodnum[]">
</div>
<div class="checkbox">
    <input type="checkbox" value="coffee" name="food[]"><label>Coffee</label>
    <input type="number" name="foodnum[]">
</div>
<div class="checkbox">
    <input type="checkbox" value="snacks" name="food[]"><label>Snacks</label>
    <input type="number" name="foodnum[]">
</div>
<div class="checkbox">
    <input type="checkbox" value="water" name="food[]"><label>Water</label>
    <input type="number" name="foodnum[]">
</div>
<div class="checkbox">
    <input type="checkbox" value="nuts" name="food[]"><label>Nuts</label>
    <input type="number" name="foodnum[]">
</div>
<div class="checkbox">
    <input type="checkbox" value="breakfast" name="food[]"><label>Breakfast</label>
    <input type="number" name="foodnum[]">
</div>
<div class="checkbox">
    <input type="checkbox" value="lunch" name="food[]"><label>Lunch</label>
    <input type="number" name="foodnum[]">
</div>
<div class="checkbox">
    <input type="checkbox" value="dinner" name="food[]"><label>Dinner</label>
    <input type="number" name="foodnum[]">
</div>
<input type="submit" name="submit" value="value">
</form>


if (isset($_POST['submit']))
{
  $foodnum=$_POST['foodnum'];
  $food=$_POST['food'];
  //$food=implode(',',$_POST['food']);
  foreach($foodnum as $index =>$value){
    $fud=$value;
    $num=$foodnum['index'];
 }
}

but when I display the variable I couldn't get the result. Can anyone help me how could store the checked items and the associated quantity together.




Aucun commentaire:

Enregistrer un commentaire