I would like to redirect the user to other page if there are no results.
what I meant like is, I am passing variables via url and using on the second page and if the the variables are empty I am able to redirect to another page.
However when the user changes the variable id in the url to something like
index.php?product-tit/=how+to+deal+with%20&%20item-id-pr=15
to index.php?product-tit/=how+to+%20&%20item-id-pr=
Nothing is displayed on the page so is there any way that I can redirect to other page in the above condition?
$title = urldecode($_GET['product-tit/']);
$id = $_GET['item-id-pr'];
$mydb = new mysqli('localhost', 'root', '', 'database');
if(empty($title) && empty($_GET['item-id-pr'])){
header('Location: products.php');
}
else{
$stmt = $mydb->prepare("SELECT * FROM products where title = ? AND id = ? limit 1 ");
$stmt->bind_param('ss', $title, $id);
$stmt->execute();
?>
<div>
<?php
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo wordwrap($row['price'], 15, "<br />
", true);
}
$mydb->close ();}
?>
</div>