douketangyouzh5219 2016-06-04 23:52
浏览 47
已采纳

从下拉菜单中选择未插入到已分配的变量[关闭]

I have used nearly this exact code on another page and it worked great, but here... not so much.

I have a drop down menu populated with elements from database columns. Whichever element is selected should be stored in the variable $Product, but for some reason I cannot figure out, it is simply not making it there and the rest of my script (parts I didn't post) doesn't work. Thanks in advance for your help.

<?php
    if(isset($_POST['submit'])) {
        $Product = $_POST['Product_List'];
    } else {
        $Product = "";
    }
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Add Chemical Inventory</title>
    </head>
    <body>
        <div id="form_div">
            <div id="form_label">
                <h2>Add Chemical Inventory</h2>
                <form action="Add_Chemical_Inventory.php">
                    <?php
                    $List = "SELECT Product_ID, Product_Name FROM `products`";
                    $list_result = mysqli_query($connection,$List); 
                    echo "Product: <select name='Product_List'>";
                    while($row = mysqli_fetch_assoc($list_result)){
                        echo "<option value='".$row['Product_ID'] ."'>".$row['Product_Name']."</option>";
                    }
                    echo "</select>";
                    echo "<br />";
                    ?>
                </form>
            </div>
        </div>
    </body>
</html>
  • 写回答

1条回答 默认 最新

  • dougan1884 2016-06-05 04:22
    关注

    You forgot the method attribute on your <form> tag.

    Thing is, by default, the method is set to get, and since your code expects post data, it just doesn't save it to the variable.

    <form action="Add_Chemical_Inventory.php" method="post"></form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀