PHP PDOException: SQLSTATE[HY093]: Invalid parameter number
Try:
$sql = "INSERT INTO persist (user_id, hash, expire)
VALUES (:user_id, :hash, :expire)
ON DUPLICATE KEY UPDATE hash=:hash2";
and
$stm->execute(
array(":user_id" => $user_id,
":hash" => $hash,
":expire" => $future,
":hash2" => $hash)
);
Excerpt from the documentation (http://php.net/manual/en/pdo.prepare.php):
You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement::execute(). You cannot use a named parameter marker of the same name twice in a prepared statement. You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement.
Binding parameters error:Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in
Hyphen "-" is a reserved character for pdo sql parser, so it must not be used in placeholder names, hence address-town and address-country are invalid names and cause the mentioned error.
Use alphanumeric characters and underscore only.
a-zA-Z0-9_
Reserved characters:
:?"'-/
See the docs https://github.com/php/php-src/blob/master/ext/pdo/pdo_sql_parser.re
PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 27
In your SQL you are using a parameter in the where clause, ":product_id", but it seems you forgot to bind it. Add the bind statement.
php error: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
You don't need to surround your parameter name with '
. Remove '
before and after :password
. Change
$query = "INSERT INTO " . $this->table_name . "
(first_name,last_name,phone,password_hash)
values (:first_name,:last_name,:phone,':password')
";
to
$query = "INSERT INTO " . $this->table_name . "
(first_name,last_name,phone,password_hash)
values (:first_name,:last_name,:phone,:password)
";
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in (xxx) PDOStatement->execute()
your statement has :used_by
$update_statement = $this->pdo->prepare("UPDATE `private_key` SET `used` = :used, `user_id` = :used_by WHERE `key` = :keyText");
But your params is providing :user
$update_statement->bindParam(':user', $id, PDO::PARAM_INT);
Related Topics
PHP Simplexml How to Save the File in a Formatted Way
PHP.Ini & Smtp= - How to Pass Username & Password
How Unique Is the PHP Session Id
Encrypt and Decrypt Text With Rsa in PHP
Where Does PHP'S Error Log Reside in Xampp
Pass JavaScript Array -≫ PHP
Checking If Date Is Weekend PHP
Issue Reading Http Request Body from a Json Post in PHP
PHP, Get File Name Without File Extension
How to Remove Line Breaks (No Characters!) from the String
Using an Array as Needles in Strpos
What's the Difference Between Isset() and Array_Key_Exists()
What's the Difference Between :: (Double Colon) and -≫ (Arrow) in PHP
How to Fix the Session_Register() Deprecated Issue
MySQL Prepared Statements With a Variable Size Variable List