executequery - PDOException thrown in PHP -
I get "SQLSTATE [HY093] error: invalid parameter number: the number of bound variables does not match the number of tokens
"When I try to run the function below:
public function find_products ($ string = '', $ fields = array), $ sort_by = '', $ sort_dir = 'ASC' ) {$ fields = empty ($ field)? '*': (''. Implode (',', $ fields) '?'); $ Binding = array ('%'. $ String. '%', '%'. $ String. '%', '%'. $ String. '%'); $ and_where_checks = array ('series', 'content'); $ And = ''; // Loop through POST variable to see what is safe to play with permission; = (array); Foreign currency ($ and_ where_a such as $ AACC) if (! $ _ POST [$ AAC])) $ $ Permission = $ AACC; If (! Empty ($ permission)) {$ tmp = array (); Forex currency ($ $ V as allowed) $ tmp = '' $ V. 'IN' ('str_pad (' ', count ($ v) * 2 - 1,'?, ').') '; $ And = 'and' ('.implode (' AND ', $ tmp).') '; Forex currency ($ $ $ as allowed) foreach ($ _POST [$ k] as $ v) $ binding = $ v; } $ Query = "SELECT" $ field "FROM" $ this- & gt; Product_table "" "WHERE" ("$." - $ sth = $ this- & gt; $ dbh- & gt; Create ($ $ Sth- & gt; Execute ($ binding); Return $ sth- & Get All (PDO :: FETCH_ASSOC);} $ POST [$ awc] The variables are filled by checkboxes on this page. When I use a checkbox group (like 1 Series and 1 material), the results are fine, but when I select multiple boxes in the same group, I get PDOException.
Does anyone know why? I still have this A I am learning so that any help would be appreciated!
query, you have only one variable Is bound (is?):
$ query = "SELECT". $ Field. "FROM". $ This- & gt; product_table. "" ($ .- $ this) - & gt; primary_key.) Like "$." and "order bye". $ Sort_by. "" $ Sort_dir; Here, you must either bind 0 or 1 More binding. How many values are there in $ bidding.
$ sth = $ this- & gt; $ dbh- & gt; Ready ($ query); $ Sth- & gt; Execution ($ binding); You can check how many values by using print_r ($ bindings) in $ bindings; Update: Without knowing your input, your code uses $ binding twice. It's set to the top with 3 values, which is the same thing: $ bindings = array ('%'. $ String. '%', '%'. $ String. '%', '%'. $ String '%'); Then below you have a foreach where you are not using the array: foreach ($ _POST [$ k] as $ v) $ binding = $ v ;
Comments
Post a Comment