Hi there,
I’ve created a form so I can search/find products but when I submit the form with no value in it…it returns data from the database…and for the life of me I can’t see why…
<?php
require_once '../connection/dbconfig.php';
include_once('../connection/connectionz.php');
//get the values
$search_products = htmlspecialchars($_POST['search_products']);
if(isset($_POST['submit'])) {
echo $search_products;
$sql = "SELECT * FROM `product` WHERE `des` LIKE '%".$search_products."%' ";
$result = mysqli_query($conDB, $sql);
echo $sql;
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)) {
echo "Name: " . $row["name"]. "<br>";
}
} else {
echo "0 results";
}
}
;?>
<form method="post" style="border:1px solid red;padding:.5em;">
<label for="search_products">Search for a product</label>
<input type="text" name="search_products" />
<input
style ="border:1px solid red;font:uppercaser;"
type="submit" name="submit" />
</form>
Any pointers will be greatly appreciated, thank you.
Darren