1
$searchTerm = isset($_GET['txtSearch']) ? $_GET['txtSearch'] : '';
$searchTerm = strtolower($searchTerm);
$searchTerm = strip_tags($searchTerm);
$searchTerm = trim($searchTerm," "); 

$keywords = explode(" ",$searchTerm); // break down search term into individual keywords

$in = join(',', array_fill(0, count($keywords), '?'));
$select = <<<SQL
    SELECT * 
    FROM m_products
    WHERE product_title IN ($in);
SQL;
$statement = $con->prepare($select);
$statement->bind_param(str_repeat('s', count($$keywords)), ...$keywords); //s = string, d = double, i = integer
$statement->execute();

I'm getting the following error from the above code:

  • Notice: Array to string conversion in
  • Notice: Undefined variable: Array in
  • Warning: mysqli_stmt::bind_param(): Invalid type or no types specified in

How do I solve this error?

2
  • $statement->bind_param(str_repeat('s', count($$keywords)), ...$keywords); has a double $$ sign Commented Jun 9, 2017 at 11:06
  • Thanks I corrected the double $$ sign and now error is solved. Commented Jun 9, 2017 at 11:14

1 Answer 1

1

As i've told in the comments above:

$statement->bind_param(str_repeat('s', count($$keywords)), ...$keywords); //s = string, d = double, i = integer

has a double $$ in the count($$keywords)) remove one $ and the error should be resolved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.