1

UPDATE ** Thank you for everyone's help. It is appreciated. It was a trigger that was being used, and not an issue with the Insert. I had tunnel visioned on the insert and forgot all about checking the trigger.


I can't for the life of me figure out the problem with this mysql insert:

INSERT INTO campaigns (camp_id,camp_name,camp_desc,camp_created,camp_creator,camp_start,camp_end,camp_active)
VALUES (null,'Clinic','2013 Clinic',now(),'user','2013-10-21','2013-10-25',1);

Table:

Field           Type          Null    Key   Default             Extra
===========================================================================================
camp_id         int(12)       NO      PRI               auto_increment
camp_name           varchar(32)   NO            
camp_desc           varchar(255)  YES           
camp_created    timestamp     NO      CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
camp_creator    varchar(16)   NO            
camp_start      date          NO            
camp_end        date          NO            
camp_active         int(1)        NO        

Any help is appreciated.

Per Requests: SHOW CREATE TABLE campaigns:

CREATE TABLE `campaigns` 
( `camp_id` int(12) NOT NULL AUTO_INCREMENT,
  `camp_name` varchar(32) NOT NULL,
  `camp_desc` varchar(255) DEFAULT NULL,
  `camp_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP 
       ON UPDATE CURRENT_TIMESTAMP,
  `camp_creator` varchar(16) NOT NULL,
  `camp_start` date NOT NULL,
  `camp_end` date NOT NULL,
  `camp_active` int(1) NOT NULL,
  PRIMARY KEY (`camp_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
3
  • A lack of inverted commas I suspect Commented Oct 3, 2013 at 17:50
  • Just checking: Is that your actual query, copy-and-pasted and accurate to the letter? Commented Oct 3, 2013 at 17:57
  • 4
    Possibly related, if you have a trigger on this table: stackoverflow.com/questions/10967063/… Commented Oct 3, 2013 at 17:58

2 Answers 2

5

You need quotes around your dates

INSERT INTO campaigns( camp_id, camp_name, camp_desc, 
                       camp_created, camp_creator, camp_start, 
                       camp_end, camp_active)
VALUES (null, 'Clinic', '2013 Clinic',
        now(), 'user', '2013-10-21',
        '2013-10-25', 1);

If you still have errors and especially the "Column Count Doesn't Match Value Count" error, then the most probable explanation is a trigger that tries to do another Insert.

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

5 Comments

Any insight why this would cause the "column count doesn't match value count" error? All it would do without the quotes is try to insert the integers 1982 and 1978 into camp_start and camp_end, respectively, no? (assuming my math is right, but you get the idea)
I had them in originally, and gotten taken out in my fiddling. :-) I added them back into the question, to avoid confusion. I'm still getting the same error, with the quotes around the dates.
Is there an Insert trigger on the table? Add the SHOW CREATE TABLE campaigns; output in your question.
Got it. It was the trigger. I just dropped the trigger and the insert went through fine. Thanks to everyone's help. How should I best mark this answered?
Maybe @ypercube likes to write up an answer.
0

Other than the error answered by juergen, you will also face an issue where you are having a column named camp_id which you have declared as NOT NULL and you are inserting NULL to it.

IF camp_id is Auto Increment then Try this::

INSERT INTO campaigns( camp_name, camp_desc, 
                       camp_created, camp_creator, camp_start, 
                       camp_end, camp_active)
VALUES ('Clinic', '2013 Clinic',
        now(), 'user', '2013-10-21',
        '2013-10-25', 1);

2 Comments

Yeah...there's the other sticking point. The camp_id is an auto_increment. I've tried putting null, '', and omitting the field altogether and still get the same error.
Made the above change, but same issue, unfortunately.

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.