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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.