1

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.

3
  • Welcome to Stack Overflow. Unfortunately, your question being too localized to be asked on this site. Please learn to find typos you your code by your own effort, especially with help from an error message you have. Please double-check if your names are all correct and match. It is not that hard. Then please delete your question. You are welcome back any time with real question on some programming problem Commented Mar 29, 2013 at 5:35
  • What a rude response. Commented Mar 30, 2013 at 1:30
  • 1
    There are no typos in the code, and it is a real programming question. Commented Mar 30, 2013 at 1:33

1 Answer 1

1

The solution is that the query was using the column name, :emailaddress, while bindValue() was referencing to :email.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.