Page 1 of 1

Problems inserting into MySql database

Posted: Wed Aug 19, 2009 12:58 pm
by jrlaughlin
I just solved a problem that I'd like to share.

I was trying to insert into my users table...simple insert using PDO:

Code: Select all

 
 
private function createNewPerson(){
    // insert into the users table
        
    $conn = Connection::getConnection();
    $st = $conn->prepare('INSERT INTO USERS ' .
                '(first_name, last_name, email_address, password, ' . 
                'password_salt, member_active, password_change_required, ' . 
                'is_administrator) VALUES (?,?,?,?,?,?,?,?)');
 
    $userData = array(
    $this->getFirstName(),
    $this->getLastName(),
    $this->getEmailAddress(),
    $this->getPassword(),
    $this->getSalt(),
    $this->isActive(),
    $this->isPasswordChangeRequired(),
    $this->isAdministrator());
 
    $st->execute($userData);
 
    print "inserted " . $st->rowCount() . " rows.\n";
    
    $conn = null;
}
 
Every time I ran this function I would get the output

Code: Select all

inserted 0 rows.
The solution was a simple one that took me several hours to figure out. The table name was "users" not "USERS".

If I wasn't bald already, I would be now...

Hope this helps somebody!

Re: Problems inserting into MySql database

Posted: Fri Aug 21, 2009 5:56 am
by planmaster
In my opinion you forgot to inser like this VALUES ("?","?","?","?","?","?","?","?")');