I'm having issues binding the LIKE
with Wildcard into my prepared statement in MySQLi. I tried both the following methods below as shown & concat.(updated with @fancyPants input)
It works without the LIKE statement.
I could only pull out data from using a certain search term. Is there anything wrong with my code?
$str = $_POST["searchstr"];
if(isset($_POST['submit']))
{
$price=$_POST['price'];
if(!empty($_POST['chkbx']))
{
foreach($_POST['chkbx'] as $selected)
{
$sql= 'SELECT bookTitle, bookPrice FROM nbc_book WHERE catID LIKE "%'.$selected.'%" AND bookTitle LIKE "%'.$str.'%" AND bookPrice < ?';
$stmt=mysqli_prepare($con,$sql);
mysqli_stmt_bind_param($stmt,"i",$price);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $bookTitle, $bookPrice);
while ($stmt->fetch()) {
echo $bookTitle.$bookPrice."<br>";
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…