1
include("config.php");
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);

if(!is_numeric($page_number)){
  header('HTTP/1.1 500 Invalid page number!');
  exit();
}
session_start();
$position = (($page_number-1) * $item_per_page);

if(!empty($_SESSION['type'])){
  $typesql = $_SESSION['type'];
  $results = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists WHERE type = ? ORDER BY score DESC LIMIT ?, ?");
  $results->bind_param("sii", $typesql, $position, $item_per_page);
  $results->execute();
  $results->bind_result($name, $location, $score, $img, $id, $type);
} else {
  $results = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists ORDER BY score DESC LIMIT ?, ?");
  $results->bind_param("ii", $position, $item_per_page);
  $results->execute();
  $results->bind_result($name, $location, $score, $img, $id, $type);
}

// Le fetch
  while($results->fetch()){
    //my cards here
  }
  ?>

I'm looking for ultimately hooking my search box to this query which is not working, I've tried to add alter the query to the below for testing purpose:

SELECT name, location, score, img, id, type FROM artists WHERE name LIKE '%etc%' ORDER BY score DESC LIMIT ?, ?

and I do have a name that has "etc" in it but the result I get is:

Call to a member function bind_param() on boolean in

How do I change this query to bind the $_GET result from the searchbox to it, the website is Setch.me

Kareem Kamal
  • 1,028
  • 1
  • 8
  • 21

1 Answers1

2

As in this question you can use LIKE with a bound parameter in mysqli:

$param = "%{$_POST['searchphrase']}%";
$stmt = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists WHERE name LIKE ?");
$stmt->bind_param("s", $param);
$stmt->execute();
$stmt->bind_result($name, $location, $score, $img, $id, $type);
WEBjuju
  • 5,797
  • 4
  • 27
  • 36