-1

I am getting a error "Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters in line ---- when i was trying to put it all in the array".

But i don't know how i can make this work. To have the bindingValues with the array working, i keep getting errors while trying.

    $text = htmlspecialchars($text);
    // prepare the mysql query to select the users
    $get_product = $connect->prepare("SELECT name FROM products WHERE name LIKE concat('%', :name, '%')  ORDER BY created DESC LIMIT ?, ? ");

    $get_product->bindValue(1, $from_record_numLiveSearch, PDO::PARAM_INT);
    $get_product->bindValue(2, $records_per_pageLiveSearch, PDO::PARAM_INT);

    // execute the query
    $get_product -> execute(array('name' => $text));

Thanks for your time and answer.

Gester
  • 113
  • 7
  • 1) You cannot mix numeric and named parameters. 2) I'm pretty sure you cannot mix `bindParam` / `bindValue` with an `execute()` array. 3) You have no `name` parameter in your query – Phil May 14 '20 at 02:26
  • How to make it work -- since you **need** the `PDO::PARAM_INT` typing for `LIMIT` params, stick with using `bindParam` / `bindValue` and use only one parameter format; named **or** positional – Phil May 14 '20 at 02:29
  • Thanks for your answer guy's. This was the first time i had to combine it so i was wondering how it workss. I forgot to post the :NAME value in the query. I EDITED my question with the right query – Gester May 14 '20 at 15:12

1 Answers1

-1

You have already added the parameters values in bindValue, so there is no need to pass array to execute function, to fix your problem try this:

//$text = htmlspecialchars($text);

$get_product = $connect->prepare("SELECT name FROM 
 products ORDER BY created DESC LIMIT ?, ? ");
$get_product->bindValue(1, 
$from_record_numLiveSearch, PDO::PARAM_INT);
$get_product->bindValue(2, 
$records_per_pageLiveSearch, PDO::PARAM_INT);
$get_product->execute();
Hardood
  • 503
  • 1
  • 5
  • 15
  • i posted the question wrong. The query also has `WHERE name LIKE concat('%', :name, '%')`. How do i combine the array 'name' with the bindValues – Gester May 14 '20 at 15:15