I need the user to select one, two, three or four items from a dropdown and then display them in the "ul". I have displayed the number of the selected item and I need to display the value.
My code
<select name="courses" size="4" multiple> <option>BMW</option> <option>Mercedes</option> <option>Audi</option> <option>Volvo</option> </select> <?php if(!isset($_POST["courses"])) { echo 'error'; } else { echo '<ul><li>' . implode('</li><li>', $_POST["courses"]) . '</li></ul>'; }...
Please don't judge strictly, I'm new to php, thanks in advance.
Set the
name attribute to the array form of "courses"
to solve the problemChange the
name="courses"
attribute toname="courses[]"
, then it will be passed to$_POST
and treated as An array, not a single-valued string.