Jump to content

How to get multiple select values through POST on php.


00stuff

Recommended Posts

Hi guys, I am trying to create a script that gets a multiple select form selections and assign them to variables with php via the POST method.

 

This is my code:

 

<select name="search_commodity[]" multiple="multiple" size="3" style="position:absolute; top:80px; left:414px; " >
<option value="all">All</option>
<option value="none">None</option>
<option value="some">Some</option>
</select>

 

 

Then after the form gets submited then it should go to this php page and the first value of the chosen options has to be assigned to the variable called commo. The problem is that is is not assigning anything.

<?php $commo = $_POST['search_commodity[0]']; ?>

 

Can someone help please? I can't figure it out.

It will return an array. Multi-dimensional arrays are in the format

 

$array['key']['subkey']

 

so you'd want to use

 

$_POST['whatever'][0]

 

That will only get you the first selected value though. You may want to read more about arrays here

http://php.net/manual/en/language.types.array.php

You may also want to read about the control structure, foreach. It's one of the easier ways to traverse through an array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.