結果がない場合は、ユーザーを別のページにリダイレクトしたいと思います。
つまり、URL を介して変数を渡し、2 番目のページで使用しています。変数が空の場合は、別のページにリダイレクトできます。
ただし、ユーザーが URL の変数 id を次のように変更すると、
index.php?product-tit/=how+to+deal+with%20&%20item-id-pr=15
にindex.php?product-tit/=how+to+%20&%20item-id-pr=
ページに何も表示されないのですが、上記の状態で別のページにリダイレクトする方法はありますか?
$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 />\n", true);
}
$mydb->close ();}
?>
</div>