Jump to content

Reading wrong data..


Darkness Soul

Recommended Posts

Hi guys,

So, new ask to you.. really need a newbie help.. ^^"!

When I print a multiple option select, and my form is sent, the $_POST just read the last one selected.. not the last click, the last down select.. a sample code like mine that's don't work too..:
[code]<?php
    if ( $_POST['component_select'] != '' )
    {
        print $_POST['component_select'] ;
    }
?>
<FORM action="teste.php" method="post">
<P>
<SELECT multiple size="10" name="component_select" STYLE="width: 500px;">
    <OPTGROUP label="Group 1">
        <OPTION value="Component_1_a">Component_1_1</OPTION>
        <OPTION value="Component_1_b">Component_1_2</OPTION>
        <OPTION value="Component_1_c">Component_1_3</OPTION>
    </OPTGROUP>
    <OPTGROUP label="Group 2">
        <OPTION value="Component_2_a">Component_2_1</OPTION>
        <OPTION value="Component_2_b">Component_2_2</OPTION>
        <OPTION value="Component_2_c">Component_2_3</OPTION>
    </OPTGROUP>
    <OPTION value="Component_3_a">Component_3</OPTION>
</SELECT>
<BR>
<INPUT type="submit" value="Send"><INPUT type="reset">
</P>
</FORM>[/code]
If I select all elements, its will print [b]Component_3_a[/b]...

Thank you for any help.. =)

D.Soul
Link to comment
Share on other sites

I've done it!!! =DDDDDDD

At PHP, the select need to write many data, but, php will read the last one... how to solute:

use [b][][/b] after the name.. why? because php will ready it like an array ;)

How we read and print an array guys?? Use [b]for [/b]or [b]foreach[/b].. =D

The code thats work well:
[code]<?php
if ( $_POST['component_select'] != '' )
{
    for ( $i = 0; $i < count ( $_POST['component_select'] ); $i ++ )
    {
        print $_POST['component_select'][$i] .'<br>';
    }
}
?>
<FORM action="teste.php" method="post">
<P>
<SELECT multiple size="10" name="component_select[]" STYLE="width: 500px;">
    <OPTGROUP label="Group 1">
        <OPTION value="Component_1_a">Component_1_1</OPTION>
        <OPTION value="Component_1_b">Component_1_2</OPTION>
        <OPTION value="Component_1_c">Component_1_3</OPTION>
    </OPTGROUP>
    <OPTGROUP label="Group 2">
        <OPTION value="Component_2_a">Component_2_1</OPTION>
        <OPTION value="Component_2_b">Component_2_2</OPTION>
        <OPTION value="Component_2_c">Component_2_3</OPTION>
    </OPTGROUP>
    <OPTION value="Component_3_a">Component_3</OPTION>
</SELECT>
<BR>
<INPUT type="submit" value="Send"><INPUT type="reset">
</P>
</FORM>[/code]
Enjoy, D.Soul
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.