I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment |
| user_id | int(4) | NO | | NULL | |
| recipient | varchar(30) | NO | | NULL | |
| subject | varchar(25) | YES | | NULL | |
| cc_email | varchar(30) | YES | | NULL | |
| reply | varchar(20) | YES | | NULL | |
| location | varchar(50) | YES | | NULL | |
| stationery | varchar(40) | YES | | NULL | |
| ink_color | varchar(12) | YES | | NULL | |
| fontchosen | varchar(30) | YES | | NULL | |
| message | varchar(500) | NO | | NULL | |
| attachment | varchar(40) | YES | | NULL | |
| messageDate | datetime | YES | | NULL |
Here are my params:
$params = array(
':user_id' => $userid,
':recipient' => $this->message_vars['recipient'],
':subject' => $this->message_vars['subject'],
':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' => $messageInput,
':attachment' => $this->message_vars['attachment'],
':messageDate' => $date );
Here is my sql:
$sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);";
And lastly, here is how I am calling it:
$dbh = parent::$dbh;
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
if (empty($dbh)) return false;
$stmt = $dbh->prepare($sql);
$stmt->execute($params) or die(print_r($stmt->errorInfo(), true));
if (!$stmt) { print_r($dbh->errorInfo()); }
I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong?