POST选择的选项值出错

时间:2016-08-10 08:59:19

标签: php html postgresql

我将此表单发布到下一个php页面,但只有默认值是发布plz帮我解决dis

<FORM name='myForm' method='post' id="myForm" action="so_entry2.php">
    <select name='select' class='selectpicker' id='select'>
        <option value='0'><------select------></option>

        <?php 
            $query11=pg_query($connect,"select emp_code, name from users where post='Dealing hand' ");
            while ($stmt11 = pg_fetch_assoc($query11))
            {  
                $emp_code=$stmt11["emp_code"];
                $emp_name=$stmt11["name"];

                print" <option value='$emp_code'>$emp_name [$emp_code]</option>";
            }
        ?>

        <option value='4'>DD</option>
        <option value='5'>JD</option>
        <option value='6'>Director</option>
        <option value='7'>VO</option>
        <option value='8'>CVO</option>  
    </select>
    <button name=forward>Forward</button> 
</form>

<?php 
if(isset($_POST['forward']))
    {    
       echo   $forward= $_POST['select'];
    }
?>

当我选择任何选项时,它仅默认值为0 现在在so_entry2.php上的下一页

点击此按钮后,只有0值发布 提前致谢

3 个答案:

答案 0 :(得分:1)

这样做。

<?php 
        $query11=pg_query($connect,"select emp_code, name from users where post='Dealing hand' ");
        while ($stmt11 = pg_fetch_assoc($query11))
        {  
            $emp_code=$stmt11["emp_code"];
            $emp_name=$stmt11["name"];
?>
        <option value='<?=$emp_code?>' >  <?=$emp_name[$emp_code]?>  </option>

<?php } ?>

答案 1 :(得分:0)

选项值包含变量,因此需要连接     

          <select name='select' class='selectpicker' id='select'>
               <option value='0'><------select------></option>

              <?php $query11=pg_query($connect,"select emp_code, name from users where post='Dealing hand' ");
              while ($stmt11 = pg_fetch_assoc($query11))
                {  $emp_code=$stmt11["emp_code"];
                    $emp_name=$stmt11["name"];

                print" <option value='".$emp_code."'>".$emp_name." </option>";
                 } ?>

          <option value='4'>DD</option>

        <option value='5'>JD</option>
         <option value='6'>Director</option>
        <option value='7'>VO</option>
        <option value='8'>CVO</option>

    </select>
        <button type="submit" name=forward>Forward</button> 

<?php if(isset($_POST['forward']))
{    
   echo   $forward= $_POST['select'];
}?>

答案 2 :(得分:0)

我不确定这个答案                       

    <select name='select' class='selectpicker' id='select'>
        <option value='0'><------select------></option>

        <?php 
            $query11=pg_query($connect,"select emp_code, name from users where post='Dealing hand' ");
              while ($stmt11 = pg_fetch_assoc($query11))
                {  $emp_code=$stmt11["emp_code"];
                    $emp_name=$stmt11["name"];
    ?>

                 <option value='<?php echo $emp_code?>'><?php echo $emp_name ?></option>
                 <?php
            }
        ?>

        <option value='4'>DD</option>
        <option value='5'>JD</option>
        <option value='6'>Director</option>
        <option value='7'>VO</option>
        <option value='8'>CVO</option> 
    </select></td><td>
    <button  class="forward"  name='forward'>Forward</button> 

    </td></tr>
</table>
</form>

<script>
    $(function(){
        $('.forward').on('click',function(e){
            e.preventDefault();
             var $target = $( e.target );
    $target.closest("form").submit();


        })
    })
</script>  

和传播页面代码

 <?php 
if(isset($_POST['select']))
    {    
       echo $forward= $_POST['select'];
    }

?>