I have looked over some of the other questions that are similar in nature to my issue, but I'm not using an array or loops in this PDO database writer script. Confused by what some of the other solutions were, I still find myself stuck on this issue.
My script is written like this:
<?php
class DatabaseWriter
{
public function writeUserToDatabase($email , $name , $age , $gender , $country , $category)
{
$host = '***********';
$dbname = 'emailcollection';
$user = '**********';
$pass = '**********';
$jointime = '2013-01-07 11:19:08';
try {
$connection = new PDO("mysql:host=" . $host . ";dbname=" . $dbname, $user, $pass);
$connection -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $connection -> prepare("INSERT INTO emailcollection (emailaddress, name, age, gender, country, category, jointime) VALUES (:emailaddress, :name, :age, :gender, :country, :category, :jointime)");
$statement -> bindValue(':email', $email);
$statement -> bindValue(':name', $name);
$statement -> bindValue(':age', $age);
$statement -> bindValue(':gender', $gender);
$statement -> bindValue(':country', $country);
$statement -> bindValue(':category', $category);
$statement -> bindValue(':jointime', $jointime);
$statement -> execute();
$connection = NULL;
}catch (PDOException $e){
echo $e -> getMessage();
}
}
}
?>
The output:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
You might be wondering what $jointime is. That is the last column in the table, and because I'm receiving something that says "Invalid parameter number", I thought that I should match the number of columns exactly (I'm trying to add a timestamp when the user is written, in PHP or SQL somehow).
Thanks for the feedback in advance.