Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2006, 09:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert fails

I am getting the following error:

Column count doesn't match value count at row 1

when I try to run this:

insert into onmylist_person values('value1', 'value2')

My table looks like this:

describe onmylist_person;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| ID | int(11) | | PRI | NULL | auto_increment |
| username | varchar(16) | | MUL | | |
| person | varchar(255) | | MUL | | |
+----------+--------------+------+-----+---------+----------------+

I know it is because I am only inserting 2 values and the table has 3, but I thought the auto_increment creted an incrementing number automatically.

I want the ID to just be a "counter" incrementing on its own, so i only have to insert the 2 fields.

How do I do this?

Mitch
__________________
Mitch
 
Old May 20th, 2006, 01:35 AM
Authorized User
 
Join Date: Mar 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Mitch,

It is simple...
just make insert statement as folows.

insert into onmylist_person values (null,'value1','value2');

and see mysql automatically inserts value for ID column.
It's really a laughing matter that primary key

 
Old May 21st, 2006, 11:36 PM
Authorized User
 
Join Date: Mar 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,
Continuing my reply......

It's really a laughing matter that we are inserting NULL for primary key col.
and Mysql (just because of auto increment) inserts a vlaue by itself.

Another way..
Table desc.
mysql> desc mytbl;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| a | varchar(15) | YES | | NULL | |
| b | varchar(15) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
mysql> insert into mytbl(a,b) values ('x','x');
Query OK, 1 row affected (0.08 sec)

Regards
Milind


 
Old June 3rd, 2006, 11:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys, that did it, I did not have enough values.

Mitch





Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT Fails teddyk ASP.NET 2.0 Basics 3 July 23rd, 2008 08:58 AM
Job Fails - trying to insert into remote machine happygv SQL Server 2000 0 March 8th, 2007 10:03 AM
BULK INSERT FAILS everest SQL Server 2000 0 February 23rd, 2006 12:55 PM
Insert Record Fails W/ Unique Constraint snw C# 0 September 2nd, 2005 02:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.