charlie
charlie

Reputation: 1384

PDO Invalid parameter number error message

i am running this PDO SQL Query:

$stmt = $pdo_conn->prepare("INSERT into ticket_updates (ticket_seq, notes, datetime, updatedby, customer, internal_message) values (:ticket_seq, :notes, :datetime, :updatedby, :customer, :internal_message) ");
                $stmt->execute(array(':ticket_seq' => $ticketnumber, 
                ':notes' => addslashes($message), 
                ':datetime' => date("Y-m-d H:i:s"),  
                ':updateedby' => $last_updated_by, 
                ':customer' => 'Y', 
                ':internal_message' => 'no'));

but getting this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /home/integra/public_html/autocheck/support_emails.php:479 Stack trace: #0 /home/integra/public_html/autocheck/support_emails.php(479): PDOStatement->execute(Array) #1 {main} thrown in /home/integra/public_html/autocheck/support_emails.php on line 479

im not sure what the issue is, all other queries work fine

Upvotes: 0

Views: 134

Answers (3)

kuroi neko
kuroi neko

Reputation: 8661

In that case you might want to use unnamed parameters. That would save you the hassle of typing them twice and improve maintenability, IMHO.

$stmt = $pdo_conn->prepare(
    "INSERT into ticket_updates (".
        "ticket_seq, notes, datetime, updatedby, customer, internal_message)". 
        "values (?, ?, ?, ?, ?, ?)");

$stmt->execute(array(
            $ticketnumber, 
            addslashes($message), 
            date("Y-m-d H:i:s"),  
            $last_updated_by, 
            'Y', 
            'no'));

Upvotes: 0

GuyT
GuyT

Reputation: 4416

Probably a typo because the error message says: parameter undefined. Double check your parameters.

Upvotes: 0

Goikiu
Goikiu

Reputation: 560

Into the prepare you call this parameter updatedby but into the bind you have updateedby fix this and maybe it solve your error.

Upvotes: 5

Related Questions