dp709369831 2019-03-19 16:31
浏览 134
已采纳

POST方法不能在同一页面上运行PHP

I know this is asked question however I have tried almost steps but its not working. I know there is a silly mistake somewhere need an experts eye. My code:

       // if(isset($_POST["country"])) 
       if($_SERVER['REQUEST_METHOD'] == "POST")
        {
            $country = $_POST["country"];

             echo '<script language="javascript">';
                echo "alert(' Officer Already Alloted..!!!');";///Tried getting alert once POST, but no message
                echo '</script>';
        }
            //? $country = $_POST["country"] : $company=1;

    ?>
        <form action="#" method="POST">
        <select class="country" name="wcpbc-manual-country" id="country" >
         <?
            $list=mysqli_query($con,"select * from country where status!='False'");
        while($row_list=mysqli_fetch_assoc($list)){
            $display="+".$row_list['phonecode']."-".$row_list['name'];
            $flag=$row_list['isosmall'];

            ?>
 <!--<select class="country" name="wcpbc-manual-country" id="country">-->

    <option value="<?$row_list['phonecode']?>" data-iconurl="https://ipdata.co/flags/<?php echo $flag; ?>.png" <?php if($country==$row_list['name']){echo "selected";} ?>><? echo $display;?></option>
    <!--<option value="IN" data-iconurl="https://ipdata.co/flags/in.png">IN some text</option>-->
    <?
        }
        ?>
    </select>
    </form>

    <script type="text/javascript">
$("#country").selectBoxIt();
</script>

Actually I am trying to get selected value on to dropdown, it seems POST is not working for assigning value to $country variable
I tried:
1. if($_SERVER['REQUEST_METHOD'] == "POST")
2. used form action="<?php echo $_SERVER['PHP_SELF']; ?>"
Please help.Thanks

  • 写回答

2条回答 默认 最新

  • dsceme82487 2019-03-19 16:36
    关注

    The <option /> values are empty:

    <?$row_list['phonecode']?>
    

    Should be

    <?php echo $row_list['phonecode']; ?>
    

    or at least

    <?= $row_list['phonecode']; ?>
    

    Also as mentioned by Always Sunny you are not visibly submitting the form. We don't know if there is Javascript going on but there must be some kind of submit action. I think you checked that in the browsers developer console.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问1553 RT怎么测试,没有BC有方法吗
  • ¥100 业务编程如何选择学习方向和内容?
  • ¥15 wamp3.3.5安装完成后图标正常显示绿色,鼠标左右键点击图标均无反应。求解决方法。
  • ¥15 鼠标点击的这条记录了什么?
  • ¥15 在写pid调速的程序时,电机始终维持最大速度
  • ¥15 【有偿】调用DXGI截图初始化失败,提示0xf 887a0004
  • ¥15 请问如何查看手机root记录?
  • ¥15 商城小程序订单号重复
  • ¥15 学校优化算法sbo和蚁群算法怎么结合
  • ¥21 matlab怎么求时域信号的二阶导数