Page 1 of 1

Column count does not match value count at row 1

Posted: Tue Jul 29, 2008 9:57 am
by big0mike
Yeah, I did Google it and found the supposed solutions but I still can't get this to work and I don't see where I have too many or too few fields as compared to the table in my database. For reference, I'm using the code from PHP Solutions: Dynamic Web Design Made Easy by David Powers. I've finally finished it and I'm now porting his code to my purpose... not well I might add 8O

Code: Select all

       // connect to database as administrator
        $conn = dbConnect('admin');
        // check for duplicate username
        $checkDuplicate = "SELECT donkey FROM donkeys WHERE email = '$email'";
        $result = $conn->query($checkDuplicate) or die(mysqli_error($conn));
        $numRows = $result->num_rows;
        // if $numRows is positive, the username is already in use
        if ($numRows) {
            $message[] = "$email is already in use. Please choose another username.";
            }
        // otherwise, it's OK to insert the details into the database
        else {
            // add an encryption key
            $key = 'key';
            // insert details into database
            $insert = "INSERT INTO donkeys (donkey, lastName, firstName, email, passWord, phone) VALUES ('', '$lastName', '$firstName', '$email', '$passWord', AES_ENCRYPT('$passWord', '$key'), '$phone')";
            // execute the query
            $result = $conn->query($insert) or die(mysqli_error($conn));
            if ($result) {
                $message[] = "Account created for $email.";
                }
            else {
                $message[] = "There was a problem creating an account for $email.";
                }
            }
        }
A SQL export of the donkeys table looks like this:

Code: Select all

CREATE TABLE IF NOT EXISTS `donkeys` (
  `donkey` int(3) unsigned NOT NULL auto_increment,
  `lastName` varchar(24) NOT NULL,
  `firstName` varchar(24) NOT NULL,
  `email` varchar(36) NOT NULL,
  `passWord` varchar(12) NOT NULL,
  `phone` varchar(12) default NULL,
  PRIMARY KEY  (`donkey`),
  UNIQUE KEY `email` (`email`),
  KEY `lastName` (`lastName`,`firstName`,`email`)
)
I know I know very little but I can't see my problem.

Thanks for any help...

Re: Column count does not match value count at row 1

Posted: Tue Jul 29, 2008 10:29 am
by big0mike

Code: Select all

$insert = "INSERT INTO donkeys (donkey, lastName, firstName, email, passWord, phone) VALUES ('', '$lastName', '$firstName', '$email', '$passWord', AES_ENCRYPT('$passWord', '$key'), '$phone')";
Should be:

Code: Select all

$insert = "INSERT INTO donkeys (donkey, lastName, firstName, email, passWord, phone) VALUES ('', '$lastName', '$firstName', '$email', AES_ENCRYPT('$passWord', '$key'), '$phone')";
It's amazing how many times I can look at something and finally give up and ask for help. And almost as soon as I hit the Submit button the solution is so obvious I wanna :banghead: