How to list all "options" selected by the user
P粉436410586
P粉436410586 2023-09-11 14:05:05
0
2
517

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.

P粉436410586
P粉436410586

reply all(2)
P粉293550575
<select name="courses[]" size="4" multiple>
    <option>BMW</option>
    <option>Mercedes</option>
    <option>Audi</option>
    <option>Volvo</option>

Set the name attribute to the array form of "courses" to solve the problem

P粉752812853

Change the name="courses" attribute to name="courses[]", then it will be passed to $_POST and treated as An array, not a single-valued string.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template