简体   繁体   中英

HTML Form is not printing right from PHP page?

I have an html page that collects data using a form with the multiple attribute, but when I try to echo out the data on the PHP page, it only echos out the last item selected.

  <select name="cars" multiple>
   <option value="car1"> BMW </option>
   <option value="car2"> TOYOTA </option>
   <option value="car3"> HONDA </option>

If I select BMW and TOYOTA, and try to echo $_POST['cars']; all it echos out is TOYOTA and not BMW. How do I get it to echo out everything that is selected?

Make select name as array type. like this and print_r($_POST['cars']);

<select name="cars[]" multiple>
   <option value="car1"> BMW </option>
   <option value="car2"> TOYOTA </option>
   <option value="car3"> HONDA </option>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM