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条)

报告相同问题?