Jump to content


Photo

error 1136: Column count doesn't match value count at row 1


  • Please log in to reply
3 replies to this topic

#1 BG1

BG1

    Active Member

  • Members
  • PipPipPipPip
  • 124 posts

Posted 14 November 2007 - 01:01 PM

I'm trying to insert values into my table, but it doesn't seem to work anymore sad.gif I get an error message stating;

"ERROR 1136 (21S01): Column count doesn't match value count at row 1"

I have no clue what it is about, googled for information, but got varying results...

This is my table;

CREATE TABLE toys (toy_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, toy VARCHAR(20));

Query OK, 0 rows affected (0.33 sec)

INSERT INTO toys (toy_id, toy) VALUES ('', 'hula hoop', '', 'balsa glider');
ERROR 1136 (21S01): Column count doesn't match value count at row 1

#2 tonyvh37

tonyvh37

    Advanced Member

  • Members
  • PipPipPipPipPipPipPipPip
  • 340 posts
  • Gender:Male
  • Location:Indiana
  • Interests:PC stuff - Gaming to Programming

Posted 14 November 2007 - 06:27 PM

Thats because you have to have two insert statements. The statement you have now is trying to insert ", 'hulahoop,'" into the toy_id column and 'balsa glider' into the toy column. what you need is something like this
INSERT INTO Toys (toy)
    VALUES ('hula hoop') /*not sure what the extra , and "" are for*/
INSERT INTO Toys (toy)
    VALUES ('balsa glider')

You don't need to insert the toy_id because you are using an auto incrementing value and the DB will take care of that. However, you cannot add more than one row into your table with one insert statement. A new row = a new insert statement. Hopefully that helps.

#3 louisc

louisc

    Active Member

  • Members
  • PipPipPipPip
  • 112 posts
  • Interests:human-machine interfaces

Posted 14 November 2007 - 09:36 PM

BG1, you have a slight syntax problem. When you want to insert multiple rows, you need to write the statement a little differently. What you should have done is this:
INSERT INTO toys (toy_id, toy) VALUES ('', 'hula hoop'), ('', 'balsa glider');

There are a few alternatives. Instead of using the somewhat confusing empty quotes, you can use DEFAULT like this:
INSERT INTO toys (toy_id, toy) VALUES
(DEFAULT, 'hula hoop'),
(DEFAULT, 'balsa glider');

Or even better, let toy_id take care of itself and write this:
INSERT INTO toys (toy) VALUES
('hula hoop'),
('balsa glider');


#4 BG1

BG1

    Active Member

  • Members
  • PipPipPipPip
  • 124 posts

Posted 15 November 2007 - 12:27 AM

I should stop working on this late at night I guess, 'cause this was a bit obvious... :oops:

Anyways, thanks again for helping me out, I was pulling hair out of my skull allready wink.gif




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users