Home > Back-end >  SQLSTATE[HY093] Invalid parameter number
SQLSTATE[HY093] Invalid parameter number

Time:01-09

I have this sql statement:

try {
    $sql = $db->prepare( 'INSERT INTO customers (UID, kundennr, salutation, fname, 
           lname, organization, email, phone, address, zip, city, CHECKED)

VALUES (:uid, :kundennr, :salutation, :fname, :lname, :organization, :email, :phone, :address, :zip, :city, CHECKED)');
        
        
    $sql->execute( array( 
        ":uid"                  => 0,
        ":kundennr"             => $customerNumber,
        ":salutation"           => $salutation,
        ":fname"                => $fname,
        ":lname"                => $lname,
        ":organization"         => $organization,
        ":email"                => serialize($emails),
        ":phone"                => serialize($phones),
        ":address"              => $address,
        ":zip"                  => $zip,
        ":city"                 => $city,
        ":checked"              => $checked
    ));
        
} catch (PDOException $e) { 
    echo $e->getMessage();
}

But I get this error:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

Where is my mistake???

CodePudding user response:

Your last value is named checked but you are executing the query with the key named :checked. Change one of them, so that the names match.

CodePudding user response:

In VALUES you have missed colon ahead of checked

Use the below sql query:

$sql = $db->prepare( 'INSERT INTO customers (UID, kundennr, salutation, fname, 
           lname, organization, email, phone, address, zip, city, CHECKED)
VALUES (:uid, :kundennr, :salutation, :fname, :lname, 
        :organization, :email, :phone, :address, :zip, :city, :checked)');
    
    
  • Related