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
https://forums.phpfreaks.com/topic/7601-reading-wrong-data/
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
https://forums.phpfreaks.com/topic/7601-reading-wrong-data/#findComment-27747
Share on other sites

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.