How can I stop an empty SQL query from displaying all results?

Modophorn

New Member
I am creating a meat packaging search form, users can search for different packages using multiple forms and dropdown boxes. I have a had a lot of problems but most of it is sorted now, I only need to create an "Any" search for the dropdown boxes and the problem of empty textboxes displaying all results. Currently when a user sends a search, they may have entered in some other text boxes, but when one of the forms is left empty that automatically displays all of the results. I want it so when a search is sent and a box is empty, the code ignores that form and just checks the ones that have info inside of them. here is my test code (not my current final form code): \[code\]<body><?php$con = mysql_connect("localhost", "root", "");mysql_select_db("delyn_db", $con);if (!$con){ die("Could not connect: " . mysql_error());}$descrip = mysql_real_escape_string($_POST['descrip']);$sql = "SELECT * FROM delyn WHERE description LIKE '%" . $descrip . "%'";$r_query = mysql_query($sql);if ($descrip === ""){ echo 'Null value';}while ($row = mysql_fetch_array($r_query)){ echo '<br /> Description: ' . $row['description'];}?></body>\[/code\]Anyone have any ideas on how to stop this?EDIT: Sorry here is my HTML with the search boxes. The above php is just where the values are sent.\[code\]<body> <form action="form5null.php" method="post"> <label for="description">Description:</label> <input type="text" name="descrip"> <br> <label for="trayheight">Trayheight:</label> <input type="text" name="height"> <br> <label for="traywidth">Traywidth:</label> <input type="text" name="width"> <br> <label for="traydepth">Traydepth:</label> <input type="text" name="depth"> <br> <label for="trayrange">Trayrange:</label> <select name="trayrange"> <option value="http://stackoverflow.com/questions/12797182/BBQ"> BBQ </option> <option value="http://stackoverflow.com/questions/12797182/Dessert"> Dessert </option> <option value="http://stackoverflow.com/questions/12797182/Display"> Display </option> <option value="http://stackoverflow.com/questions/12797182/Meat"> Meat </option> <option value="http://stackoverflow.com/questions/12797182/Microwave"> Microwave </option> <option value="http://stackoverflow.com/questions/12797182/Party"> Party </option> <option value="http://stackoverflow.com/questions/12797182/Salad/Wet Pasta"> Salad/Wet Pasta </option> <option value="http://stackoverflow.com/questions/12797182/Snacks"> Snacks </option> <option value="http://stackoverflow.com/questions/12797182/Standard"> Standard </option> </select> <label for="traytype">Traytype:</label> <select name="traytype"> <option value="http://stackoverflow.com/questions/12797182/Open"> Open </option> <option value="http://stackoverflow.com/questions/12797182/Cavitised"> Cavitised </option> <option value="http://stackoverflow.com/questions/12797182/Lid"> Lid </option> <option value="http://stackoverflow.com/questions/12797182/Tray"> Tray </option> <option value="http://stackoverflow.com/questions/12797182/Coallition"> Coallition </option> <option value="http://stackoverflow.com/questions/12797182/Bowl"> Bowl </option> <option value="http://stackoverflow.com/questions/12797182/Hinge pack"> Open </option> <option value="http://stackoverflow.com/questions/12797182/Pot"> Pot </option> <option value="http://stackoverflow.com/questions/12797182/Base & Lid"> Base and Lid </option> <option value="http://stackoverflow.com/questions/12797182/Rectangular"> Rectangular </option> <option value="http://stackoverflow.com/questions/12797182/Specalist"> Specialist </option> </select> <br> <label for="trayshape">Trayshape:</label> <select name="trayshape"> <option value="http://stackoverflow.com/questions/12797182/Rectangular"> Rectangular </option> <option value="http://stackoverflow.com/questions/12797182/Oval"> Oval </option> <option value="http://stackoverflow.com/questions/12797182/Square"> Square </option> <option value="http://stackoverflow.com/questions/12797182/Insert"> Insert </option> <option value="http://stackoverflow.com/questions/12797182/Round"> Round </option> <option value="http://stackoverflow.com/questions/12797182/Open"> Open </option> </select> <br /> <input type="submit" value="http://stackoverflow.com/questions/12797182/Submit"> </form></body>\[/code\]
 
Back
Top