#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Location
    Atlanta, GA, USA (unfortunately)
    Posts
    66
    Rep Power
    6

    Question PDO: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined


    Hello all,

    I have been utterly stumped trying to figure out why I am getting this error about invalid parameter numbers when connecting to mySQL database. Again, the error message is as follows:

    SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
    PHP Code:
    <?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_ERRMODEPDO::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();
                }
            }
        }
    ?>
    You may be wondering what $jointime is. I want to add a timestamp when the user signs up, but I also just put this in temporarily to match the columns exactly as they appear in phpMyAdmin.

    Thanks for the suggestions!
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,733
    Rep Power
    1959
    SQL statement has :emailaddress, bindValue use :email

    Comments on this post

    • etidd agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Location
    Atlanta, GA, USA (unfortunately)
    Posts
    66
    Rep Power
    6

    Talking


    Thank you, Mr. Fujin. After 2 days I couldn't find that. Wow! It works!

    I'm gonna come hang out and build a reputation over here at DevShed. I look forward to helping answer other people, too!

    Comments on this post

    • MrFujin agrees : here some points to get your reputation started :)

IMN logo majestic logo threadwatch logo seochat tools logo