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 脱敏项目合作,ner需求合作
  • ¥15 脱敏项目合作,ner需求合作
  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密