skip to Main Content

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???

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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)');
        
        
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search