This question already has an answer here:
- Getting checkbox values on submit 10 answers
I am trying to post values from multiple checkboxes into table. Unfortunately, I am getting an error which says:
Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/WDT/survey.php on line 6
Here is my form:
<form action="survey.php" method="POST">
<div class="input-select">
<h3>Preferred mode of transport</h3>
<select name="transportMode">
<option value="Car">Car</option>
<option value="Bus">Bus</option>
<option value="Tram">Tram</option>
<option value="Train">Train</option>
</select>
</div>
<div class="input-radio">
<h3>Chosen mode of transport to hostel</h3>
<input type="radio" name="transportToHostel" value="car"> Car<br>
<input type="radio" name="transportToHostel" value="taxi"> Taxi<br>
<input type="radio" name="transportToHostel" value="other"> Other
</div>
<div class="input-checkbox">
<h3>Required room equipment</h3>
<input type="checkbox" name="requiredEquipment" value="double bed"> Double Bed<br>
<input type="checkbox" name="requiredEquipment" value="kettle"> Kettle<br>
<input type="checkbox" name="requiredEquipment" value="tv"> TV
</div>
<input type="submit" text="Send">
</form>
And PHP script:
if (!empty($_POST['transportMode'])) {
echo 'Transport Mode: '.$_POST['transportMode'].'<br>';
}
if (!empty($_POST['transportToHostel'])) {
echo 'Transport to Hostel: '.$_POST['transportToHostel'].'<br>';
}
if(!empty($_POST['requiredEquipment'])) {
foreach($_POST['requiredEquipment'] as $equipment){
$equipment_required .= $equipment.',';
echo "value : ".$_POST.'<br/>';
}}
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire