dphs48626 2015-10-15 03:15
浏览 391

获取Bootstrap下拉值以保存到数据库并显示在表中

I'm having trouble getting a Bootstrap ul li list to store values to a database on click, and then display them. I have my index page with some fields and then dropdowns. The user puts text into the fields and selects from the dropdown, when you click the button the page is refreshed and the data is displayed in a table.

I don't want to use because I want to style the dropdown consistently.

When I tested it with it saved the data, but no luck with an unordered list.

I've searched for the solution to this and read documentation but can't find any information that might match my setup and I'm not fluent in PHP. Here are some snippets. If more is needed I'll provide. Thanks for reading.

Form:

<form action="parts/insert.php" method="post" role="form">
    <select name="prep" id="prep">
        <option value="">Preparation</option>
        <option value="0 - 10 mins" >0 - 10 minutes</option>
        <option value="11 - 30 mins">11 - 30 minutes</option>
        <option value="One hour +">One hour +</option>
    </select>

    <input class="submit btn btn-block btn-lg btn-primary" name="submit" type="submit" value="Add" />
</form>

Where the issue seems to be:

<?php 
    $query = mysql_query("SELECT `id`, `prep`, FROM `food` ORDER BY food ASC");
    while($row = mysql_fetch_array($query)) {
?>

<tr>
    <td><?php echo $row['prep']; ?></td>
</tr>

insert.php:

    $connection = mysql_connect("hostname", "username", "password");

    $db = mysql_select_db("databasename", $connection);

if(isset($_POST['submit'])){
    $prep = $_POST['prep'];
    if($food !=''){
        $query = mysql_query("insert into food(prep) value ('$prep')");
        require_once header("Location: ../index.php");
    } else {
        echo "<p>Please fill out all fields</p>";
    }
}

mysql_close($connection);
  • 写回答

1条回答 默认 最新

  • dongnaigu2052 2015-10-15 05:58
    关注

    As misterManSam said, look into MySQLi or PDO as a new method.

    It looks like $food isn't being defined in your form action so your query is not running. You may have meant to type $prep:

    if(isset($_POST['submit'])){
        $prep = $_POST['prep'];
        if($prep !=''){
            $query = mysql_query("insert into food(prep) value ('$prep')");
            require_once header("Location: ../index.php");
        } else {
            echo "<p>Please fill out all fields</p>";
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog