473,746 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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','Chan dler','','','La
Mirada','CA',90 638,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 10769
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','Chan dler','','','La Mirada','CA',90 638,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($qu ery);
if(!mysql_num_r ows($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','Chan dler','','','La
Mirada','CA',90 638,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','Chan dler','','','La
Mirada','CA',90 638,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
1691
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) DECLARE @cmd VARCHAR(500) set @Table = 'tblManager' set @Email = 'cauer@tampabay.rr.com'
4
14075
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
4046
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 can be true). So I've created a class inheriting from DataGridColumnStyle and added the following code to the class: protected RadioButton rb ; ....
1
2648
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 columns, but returns an empty string for the cells that are hyperlink columns. Here is the code to retrive the text: Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
0
4096
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, TYPE VARCHAR(30) NOT NULL, DURATION TIME , YEAR_RELEASE YEAR NOT NULL, DESCRIPTION TEXT,
23
2893
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 it is optimal. thanks int k = 0;
5
5510
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 are uniqueidentifier columns. My questions: - is Type="Object", below, necessary? - what shall I specify for DefaultValue in my function? I tried everything.
22
12486
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=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
1
1789
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 colnum="1" colname="col1"/> <colspec colnum="2" colname="col2"/> <colspec colnum="3" colname="col3"/>
0
8975
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8801
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9516
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9351
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9286
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6062
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4587
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.