Hi I hope someone can help. This is my first attempt at using SQL and I'm finding a challenge, to say the least. What I am trying to do is to write multiple searches for a motorcycle website the customer would enter
- make in box 1 model in box 2 product in box 3 year in bod 4
But I stuck trying to match multiple words in any order, customers have to type the exact phrase for it to find the product.
this is the code so far
Thanks for your help in advance
<?php
include 'motorcyclefitmentdb.php';
?>
<center>
<table id="search_box">
<form method="post">
<td><input name="Make" type="text" placeholder="Make....." value="<?php echo isset($_POST['Model']) ? htmlspecialchars($_POST['Make'], ENT_QUOTES) : ''; ?>">
</td>
<td><input name="Model" type="text" placeholder="Model....." value="<?php echo isset($_POST['Model']) ? htmlspecialchars($_POST['Model'], ENT_QUOTES) : ''; ?>">
</td>
<td><input name="Item" type="text" placeholder="Item....." value="<?php echo isset($_POST['Item']) ? htmlspecialchars($_POST['Item'], ENT_QUOTES) : ''; ?>">
</td>
</td>
<td><input name="Year" type="text" placeholder="Year....." value="<?php echo isset($_POST['Year']) ? htmlspecialchars($_POST['Year'], ENT_QUOTES) : ''; ?>"></td>
<td><button type="submit" name="submit search">Submit</button></td>
</form>
</table>
</center>
<br><br>
</div>
<center>
<table class = "customer">
<?php
if(isset($_POST['submit-search'])){
$Make = $_POST['Make'];
$Model = $_POST['Model'];
$Item = $_POST['Item'];
$Year = $_POST['Year'];
$sql = "SELECT * FROM `fitment` WHERE `Make` LIKE '%$Make%'
AND `Model` LIKE '%$Model%'
AND `Item` LIKE '%$Item%'
AND `Year Search` LIKE '%$Year%'
";
$stmt = $conn->prepare($sql=presql);
$newsql = presql;
$stmt->bindPram("presql", $newsql, PDO::PARAM_CHAR);
$stmt->execute();
}
if ($stmt->num_rows > 0) {
// output data of each row
while($row = $stmt->fetch_assoc()) {
echo
"
<tr>
</tr><td>
".$row["Image"]."
<br><br>
".$row["Item"]."
<br><br>
SKU: ".$row["SKU"]."
<br>
£ ".$row["Price"]."
<br><br>
".$row["Buy"]."
</td>
<td>
".$row["Make"]." ".$row["Model"]." ".$row["Year"]."
<br><br>
".$row["Engine"]."
</td>
</tr>
";
}
} else {
echo "0 results";
}
$conn->close();
?>
</table>
</center>
</div>