lundi 3 octobre 2016

How do I use PHP to query my SQL database using SELECT tag in html

Basically I'd like to use the choices which the user has selected from a different select tags, and in essence store these as variables which I can then use to query my database in SQL.

My HTML code is here:

            <img  src="UniSelect.jpeg">

                <select>
                    <option selected disabled>Select a university</option>
                    <option value="ucl">UCL</option>
                    <option value="kings">Kings College</option>
                    <option value="imperial">Imperial College</option>
                    <option value="lse">London School of Economics</option>
                </select>

        <img  src="PriceSelect.jpeg">

                <select>
                    <option selected disabled>Select a weekly rent price</option>
                    <option value="50">0-£50</option>
                    <option value="100"> £100-£150</option>
                    <option value="150">£150-200</option>
                    <option value="200"> £200+</option>
                </select>

And the type of php i would be looking to use would be:

     //$con=mysqli_connect("localhost","adam","YjM3ZTYwOTQ5OWRmYWZh","adam_...");
    // Check connection
    //if (mysqli_connect_errno())
    //  {
    //  echo "Failed to connect to MySQL: " . mysqli_connect_error();
    //  }

    // Perform queries 
    //$sql=mysqli_query($con,"SELECT CONTENT FROM Blog WHERE ID = 01");
    //$result=mysqli_fetch_assoc($sql);



    //echo $result['CONTENT'];

    //mysqli_close($con);

To make it clear once more, I want to use the different values which the user selects, upon clicking a search button, have these query results shown in a table.




Aucun commentaire:

Enregistrer un commentaire