还有一个 - PDO INSERT警告:PDOStatement :: execute() - SQLSTATE [HY093]:参数号无效:参数未在

I've checked my code over and over, looking for typos, and checked all the answers here and have not found an answer for this PDO insert warning. Here are my db columns:

 id (autoincrement), user_id, recipient, cc_email, reply, location, stationery, ink_color, fontchosen, message, attachment, messageDate.

Here is the output from my POST variables:

field is recipient and value is 123 
field is cc_email and value is  
field is reply and value is No 
field is location and value is heaven 
field is fontchosen and value is Arial 
field is attachment and value is 
field is message and value is abc 
field is stationery and value is images/stationery/patriotic.jpg

I calculate the user_id below this. The values that are blank above, can be NULL in the db. I check for default values (for instance ink_color) after the POST and add default values.

This is my sql printed to error_log:

sql is INSERT INTO messages (user_id,recipient, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment, messageDate ) VALUES( 4, :recipient, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, :message, :attachment, NOW());

These are my params:

      $params = array(
        ':userid' => $userid,
    ':recipient' => $this->message_vars['recipient'],
        ':cc_email' => $this->message_vars['cc_email'],
        ':reply' => $this->message_vars['reply'],
    ':location' => $this->message_vars['location'],
    ':stationery' => $this->message_vars['stationery'],
        ':ink_color' => $this->message_vars['ink_color'],
        ':fontchosen' => $this->message_vars['fontchosen'],
        ':message' => $this->message_vars['message'],
    ':attachment' => $this->message_vars['attachment']
    );

There are 11 values for 11 columns, plus the id (auto increment). Can anyone see a problem with my PDO statement?

There is no :userid in your query, even though you bound it. That is the cause of the problem.

This sort of thing would be easier to spot if you used a few newlines and lined your code up nicely…