Jump to content


Photo

Reading wrong data..


  • Please log in to reply
1 reply to this topic

#1 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 17 April 2006 - 02:52 PM

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..:
<?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>
If I select all elements, its will print Component_3_a...

Thank you for any help.. =)

D.Soul
(If something is wrong, please tell me. I'm learning this language. Thank you)

#2 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 17 April 2006 - 04:53 PM

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 [] after the name.. why? because php will ready it like an array ;)

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

The code thats work well:
<?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>
Enjoy, D.Soul
(If something is wrong, please tell me. I'm learning this language. Thank you)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users