0

我正在尝试将选定的下拉值存储在会话变量中,并且每次打印我在其他页面上使用的变量时,它都会显示我基​​本上从中填充下拉列表的数组的最后一个值。这是代码;

<?php $options = array('2CHECKOUT','PAYPAL'); ?>

<select name="payment" style="width:225px;" id ="mySelect">
    <?php foreach($options as $opt) { ?>
        <?php $selected = (isset($_SESSION['payment']) && $opt == $_SESSION['payment']) ? ' SELECTED' : '';
        echo '<option value="'.$opt.'"' .$selected.'>'.$opt.'</option>'; ?>
    <?php } ?>
    <?php error_log("the session var".print_r($_SESSION['payment'])); ?>
</select> </div> 

有人可以帮助我吗?

4

1 回答 1

-1

将您的代码更改为

<?php $options = array('2CHECKOUT','PAYPAL'); ?>

<div>
<select name="payment" style="width:225px;" id ="mySelect">
    <?php foreach($options as $opt) { ?>
        <?php $selected = (isset($_SESSION['payment']) && $opt == $_SESSION['payment']) ? ' SELECTED' : '';
        echo '<option value="'.$opt.'"' .$selected.'>'.$opt.'</option>'; ?>
    <?php } ?>

</select> 
<?php error_log("the session var".print_r($_SESSION['payment'])); ?>
</div> 
于 2013-02-13T10:29:33.397 回答