下拉,结果表没有显示Mysql php

时间:2015-04-20 05:54:46

标签: php sql mysqli

尝试将Mysql的结果显示在网页上。
过程是用户选择汽车品牌,然后它将在表格中显示该品牌。 我一直在尝试不同的东西,但似乎无法让它显示结果。一旦我摆脱了sql查询中的WHERE语句,它就会显示所有的汽车/品牌。我认为问题出在sql语句或if中。

这是我到目前为止所得到的。

       <HTML > 

          <head> 
            <title>Inventory</title> 

          </head> 
          <body>


          <form method="get" action="TaskC.php">
                Please select a make:   
                    <select name = "make" >
                    <option value = "All">All</option>
                    <option value = "Toyota">Toyota</option>
                    <option value = "Holden">Holden</option>
                    <option value = "Ford">Ford</option>
                    <option value = "Nissan">Nissan</option>

                </select> <br/>

                <br/> 
            <input type="submit" value="Search" name="Search" />

          <table width="600" border="1" cellpadding="1" cellspacing="1">
          <tr>
          <th>Make</th>
          <th>Model</th>
          <th>Price</th>
          <th>Quantity</th>
          <tr>
          </form>

        <?php 
         //error_reporting (E_ALL ^ E_NOTICE);
        $dbConnect = mysqli_connect('xxxxxxxxx', 'xxxxxxxxx','xxxxxxxx')
        or die("<p>The database server is not available.</p>");
        $dbSelect = mysqli_select_db( $dbConnect,'xxxxxxxx_db' )
        or die("<p>The database is not available.</p>");


           $make = $_GET['make'];


        $sqli = "SELECT * FROM inventory WHERE make = '" .$make. "'";
         $result = mysqli_query($dbConnect,$sqli);
        if (isset($_GET['make']) )

        {

        while ($inventory = mysqli_fetch_assoc($result) )
            {

            echo  "<tr>";

            echo "<td>".$inventory['make']."</td>";

            echo "<td>".$inventory['model']."</td>";

            echo "<td>".$inventory['price']."</td>";

            echo "<td>".$inventory['quantity']."</td>";

            echo  "</tr>";


            }
            }   
mysqli_close($dbConnect);   
            ?>

        </body> 

        </HTML>

希望你能提供帮助。 感谢

1 个答案:

答案 0 :(得分:0)

查询中有错误。它应该是 -

$sqli = "SELECT * FROM inventory WHERE make = '" .$make. "'";

修改

if (isset($_GET['make']) ){
    $make = $_GET['make'];


        $sqli = "SELECT * FROM inventory WHERE make = '" .$make. "'";
         $result = mysqli_query($dbConnect,$sqli);


        while ($inventory = mysqli_fetch_assoc($result) )
            {

            echo  "<tr>";

            echo "<td>".$inventory['make']."</td>";

            echo "<td>".$inventory['model']."</td>";

            echo "<td>".$inventory['price']."</td>";

            echo "<td>".$inventory['quantity']."</td>";

            echo  "</tr>";


        }
}