473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Column count doesn't match value count error

Hi,

I'm trying to do an insert with the following statement:

INSERT INTO user VALUES ( 'a*@ag.com','ag','Aaron','Chandler','','','La
Mirada','CA',90638,714,'','');

and I'm getting the error message "Column count doesn't match value
count at row 1".

My table schema is:
Field Type Null Default
------------------------------------------------
email varchar(50) No
password varchar(50) No
f_name varchar(30) No
l_name varchar(40) No
address_1 varchar(50) Yes NULL
address_2 varchar(50) Yes NULL
city varchar(30) No
state char(2) No
zip mediumint(5) No 0
home_area smallint(3) No 0
home_phone varchar(7) Yes NULL
comments text Yes NULL
I have 12 fields in my table (the first being the primary key), and the
syntax seems correct here. Any ideas why this message could be appearing?

Thanks,
Aaron
Jul 20 '05 #1
5 10746
Aaron C wrote:
I have 12 fields in my table (the first being the primary key), and the
syntax seems correct here. Any ideas why this message could be appearing?


I don't understand that sentence. Do you have 12 or do you have 13
fields? I tested your query with 12 fields and it worked fine. If you
have an extra id field in your table, then your query won't work.
Solution in that case might be giving null as a value for that field in
your insert-sentence.

Here's what I tried:

mysql> create table user(
-> email varchar(50),
-> password varchar(50),
-> f_name varchar(30),
-> l_name varchar(40),
-> address_1 varchar(50),
-> address_2 varchar(50),
-> city varchar(30),
-> state char(2),
-> zip mediumint(5),
-> home_area smallint(3),
-> home_phone varchar(7),
-> comments text
-> );
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO user VALUES (
'a*@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'','');
Query OK, 1 row affected (0.00 sec)
Jul 20 '05 #2
Alright, I recreated the table in PHPMyAdmin using:

CREATE TABLE `user` (
`email` VARCHAR( 50 ) NOT NULL ,
`password` VARCHAR( 50 ) NOT NULL ,
`f_name` VARCHAR( 30 ) NOT NULL ,
`l_name` VARCHAR( 30 ) NOT NULL ,
`address_1` VARCHAR( 50 ) NOT NULL ,
`address_2` VARCHAR( 50 ) NOT NULL ,
`city` VARCHAR( 30 ) NOT NULL ,
`state` CHAR( 2 ) NOT NULL ,
`zip` MEDIUMINT( 5 ) NOT NULL ,
`home_area` SMALLINT( 3 ) NOT NULL ,
`home_phone` VARCHAR( 8 ) NOT NULL ,
`comments` TEXT NOT NULL
);

not allowing nulls for the time being.

I then executed the following:
$query = "INSERT INTO user VALUES
('x',password('x'),'x','x','x','x','x','x',11,11,' x','x');";
$result = mysql_query($query);
if(!mysql_num_rows($result)) echo mysql_error();
else echo "Inserted the data!";

There are 12 rows in the table, and 12 arguments passed to the INSERT
command. The types match, but I'm still getting the message "Column
count doesn't match value count at row 1". What is going on here? This
is maddening!

Thanks,
Aaron

Aggro wrote:
Aaron C wrote:
I have 12 fields in my table (the first being the primary key), and
the syntax seems correct here. Any ideas why this message could be
appearing?

I don't understand that sentence. Do you have 12 or do you have 13
fields? I tested your query with 12 fields and it worked fine. If you
have an extra id field in your table, then your query won't work.
Solution in that case might be giving null as a value for that field in
your insert-sentence.

Here's what I tried:

mysql> create table user(
-> email varchar(50),
-> password varchar(50),
-> f_name varchar(30),
-> l_name varchar(40),
-> address_1 varchar(50),
-> address_2 varchar(50),
-> city varchar(30),
-> state char(2),
-> zip mediumint(5),
-> home_area smallint(3),
-> home_phone varchar(7),
-> comments text
-> );
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO user VALUES (
'a*@ag.com','ag','Aaron','Chandler','','','La
Mirada','CA',90638,714,'','');
Query OK, 1 row affected (0.00 sec)

Jul 20 '05 #3
Aaron C wrote:
INSERT INTO user VALUES ( 'a*@ag.com','ag','Aaron','Chandler','','','La
Mirada','CA',90638,714,'','');


I generally recommend naming the fields in an insert statement, in
addition to the values. That way if you add a field or change the order
of the fields your INSERT statement won't break. It sounds like exactly
that has happened in your case; there's actually more fields that the 12
values you have provided.

For example:

INSERT INTO user (email, password, f_name, l_name,
address_1, address_2, city, state, zip,
home_area, home_phone, comments)
VALUES ( 'a*@ag.com', 'ag', 'Aaron', 'Chandler',
'', '', 'La Mirada', 'CA',90638,
714, '', '');

Regards,
Bill K.
Jul 20 '05 #4
Aaron C wrote:
Alright, I recreated the table in PHPMyAdmin using:

CREATE TABLE `user` ( $query = "INSERT INTO user VALUES


I tried that at both of my servers, other is 3.x and other is 4.1.7

And they both worked fine with the example queries you provided. But I
used the mysql command line tool, perhaps you should try that also?

But in case you are tired of fighting with this, you could actually try
to do it this way:

INSERT INTO user(field1, field2, ...) VALUES ('value1', 'value2', ...);

So give name for each field you are going to use. If that also fails,
try doing it again, but this time with less fields. Or start with 1
field, and then add 1 after another untill you get error. That might
help locating the problem.
Jul 20 '05 #5
Found out what it was a little bit ago...
The database name wasn't being passed properly to my db_connect()
function. Oops!

Anyway, thanks for the help, both of you.

Aaron

Aggro wrote:
Aaron C wrote:
Alright, I recreated the table in PHPMyAdmin using:

CREATE TABLE `user` (


$query = "INSERT INTO user VALUES

I tried that at both of my servers, other is 3.x and other is 4.1.7

And they both worked fine with the example queries you provided. But I
used the mysql command line tool, perhaps you should try that also?

But in case you are tired of fighting with this, you could actually try
to do it this way:

INSERT INTO user(field1, field2, ...) VALUES ('value1', 'value2', ...);

So give name for each field you are going to use. If that also fails,
try doing it again, but this time with less fields. Or start with 1
field, and then add 1 after another untill you get error. That might
help locating the problem.

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Auer | last post by:
I am trying to run a query where my Table and my request are variables (Will be used in Stored Procedure) Declare @Email VARCHAR(100) Declare @Table VARCHAR(50) Declare @Count VARCHAR(8)...
4
by: Laszlo Csabi | last post by:
Hi Folks, Can someone explain me why I'm getting the following error? The error message I got is : "Parameter count does not match Parameter Value count."
1
by: Dmitry V. Markin | last post by:
Good day! Here is my problem: I need to have a radiobutton column in my DataGrid for a representation of a bool column, where only row can be checked at one time(only one value in bool column...
1
by: jeguillo | last post by:
I am trying to retrieve the text within each cell in a datagrid in order to change the color of each cell, depending on the value within that cell. This works fine on the cells that are bound...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
5
by: John | last post by:
I just cannot manage to perform a SELECT query with NULL parameter... My CATEGORY table does have one row where TCATEGORYPARENTID is null (real DB null value). TCATEGORYID and TCATEGORYPARENTID...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
1
by: Byomokesh | last post by:
Hi I am trying to cell count and match in tgroup cols value in XML file. if cell count and tgrou cols value is mismatch, its showing error. My xml -------------- <tgroup cols="3"> <colspec...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.