-1

My php code isnt displaying the multiple options that I select. What am I doing wrong ?

This is the code inside my form.html

<html>
<p>Your chosen food: <select name="food[]" size="6" multiple="multiple">
<option value="noodles">noodles</option>
<option value="pizza">pizza</option>
<option value="seafood">seafood</option>
<option value="fish">fish</option>
<option value="lamb">lamb</option>
</select>
</p>
</html>

this is my php code inside form.php

<?php
$foodstr = $_POST["food"];
?>

<p><strong>chosen food = </strong> <?php echo  count($_POST["chosenfood"]) ?></p>; 
user3500239
  • 31
  • 1
  • 1
  • 6

1 Answers1

1

Use this code:

<?php
$foodstr = $_POST["food"];
echo "You selected: ", implode(', ' $foodstr);
?>

It will return a string like this:
You selected noodles, pizza, seafood, fish

Al.G.
  • 4,327
  • 6
  • 31
  • 56