Skip to content
Advertisement

I can’t get multiple selected values of select box in php

So, I have an HTML/PHP form that has a select list box from which you can select multiple values because its multiple properties are set to multiple. Consider the form method is ‘POST’. But the list box is saving only one value when I click on SUBMIT (to be specific the last value chosen). I don’t know why.

This is part of my code:

JavaScript

Advertisement

Answer

the code work just right for me:

JavaScript

have some special config in PHP?

my test:

JavaScript

edit:

when yo receive array data in PHP, in your case:

JavaScript

the PHP var is $_POST['classes'] not $_POST['classes[]'] and it is an array, if you want to use it as an string you have to use implode

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement