未从下拉列表中获得所需的值 PHP

Not getting desired value from dropdown PHP

我正在尝试更新页面以在用户从下拉列表中的国家/地区列表中选择一个值后显示所选国家/地区。当我尝试回显 $selected_country 时,值为“”。出于某种原因,当表单提交时,值没有被更新。有人可以帮忙吗?

<div class="row pt-4 pb-4">
            <div class="col-4">
                <h2 class="table_title">Travel Restrictions</h2>
                <p class="table_title">
                    See what countries you can travel to.
                    <?php if (isset($_POST['submit_dropdown'])) {
                                $selected_country = $_POST['submit_dropdown'];
                                echo $selected_country;
                    }
                      ?>
                </p>
            </div>

            <div <?php echo $css_tag_dropdown ?>>
                <div class="text-center">
                    <p class="table_title">
                        Select the originating country.
                    </p>
                    <form method="post">
                        <select class="form-control" name="submit_dropdown" onchange="this.form.submit();">
                            <option selected>Select country</option>
                            <?php while ($row = mysqli_fetch_array($dropdown_origins)) :; ?><option value=""><?php echo $row[0]; ?></option><?php endwhile; ?>
                        </select>
                    </form>
                </div>
                <div class="col"></div>
            </div>
        </div>

$_POST['submit_dropdown'] 包含所选选项的 value 属性,因此您应该根据国家/地区在 while 循环中填充它:

<option value="<?php echo "$row[0] country code here"; ?>"><?php echo $row[0]; ?></option>