sql - Drop down, results table not showing Mysql php

76

Trying to get the results from the Mysql to show up on the web page.
The process is that the user would select a make of a car and then it will show just that make in a table. I've been trying different things but I cant seem to get it to show the results. As soon as I get rid of the WHERE statement in the sql query it shows all the cars/makes. I think the problem is in the sql statement or the if.

This is what I've got so far.

       <HTML > 

          <head> 
            <title>Inventory</title> 

          </head> 
          <body>


          <form 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>

Hope you can help. Thanks

413

Answer

Solution:

There is an error in the query. It should be -

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

Edit

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>";


        }
}   

People are also looking for solutions to the problem: php - How to generate absolute URL path to a script file?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.