$_POST[''] variable question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imme
Forum Newbie
Posts: 14
Joined: Fri Nov 21, 2003 11:51 am

$_POST[''] variable question

Post by imme »

Hi,
I got the following code:

Code: Select all

pulldown(employee,pulldown_l,getContacts(employee,name),k_nr,firstname,name);
it calls this function:

Code: Select all

function pulldown($name, $style, $source, $index, $value1, $value2, $value3)
{
    $index_array=array();
    $value1_array=array();
    $value2_array=array();
    $value3_array=array();

    while($row=@mysql_fetch_array($source))
    { 
        array_push($index_array,$row[$index]);
        array_push($value1_array,$row[$value1]); 
        array_push($value2_array,$row[$value2]);
        array_push($value3_array,$row[$value3]); 
    }
    
    echo '<select name="' . $index . '" size="1" class="' . $style . '">';
    echo '<option>' . $name . '</option>';
    echo '<option disabled></option>';
    for($i=0;$i<count($index_array);$i++)
    {
        echo '<option value="' . $index_array[$i] . '"';
        if ($_POST[$index]==$index_array[$i]) { echo ' selected="selected"'; }
        echo '>';
        echo $value1_array[$i] . ' ' . $value2_array[$i] . ' ' . $value3_array[$i] . '</option>';
    }    
    echo '</select>';
}
It all works fine except for the "if" that is supposed to mark the current value of the option's variable "selected".

Code: Select all

if ($_POST[$index]==$index_array[$i]) { echo ' selected="selected"'; }
index is the name of the option tag and results in the $_POST['name'] variable. It does not work, though. Putting it like this

Code: Select all

$_POST['$index']
does work either.

Thanks for your help.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

$_POST['$index'] doesn't evaluate. You need just $_POST[$index] or $_POST["$index"].

Try echoing $_POST[$index] and $index_array[$i] each loop and look at the result.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

doh! didnt' read carefully enough...

yes try echoing them out :?
Post Reply