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粉2935505752023-09-12 13:16:49
<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粉7528128532023-09-12 10:36:48
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.