954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

insert statement error

hi,

I have a table called shoutbox, i created it this way:

CREATE TABLE `shoutbox` ( `id` INT NOT NULL AUTO_INCREMENT ,
`ip` varchar(20) NOT NULL ,
`name` varchar(30)  NOT NULL ,
`url` varchar(30)  NOT NULL ,
`message` varchar(50)  NOT NULL ,
`date` date  NOT NULL ,
PRIMARY KEY ( `id` ) );


but when i want to insert into it some values using following command :

insert into shoutbox values(1, 6546556, sam, something.com,skdsd,23-02-07);


I get the following error:

error 1054(42s22): unkown colum 'sam' in 'field list'


ps. i am using mysql 5.0

thanks

sam1
Posting Whiz
300 posts since Nov 2004
Reputation Points: 10
Solved Threads: 1
 

6 fields in your table but u inert only 5 values
char must be single quote

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

hi,

I have a table called shoutbox, i created it this way:

CREATE TABLE `shoutbox` ( `id` INT NOT NULL AUTO_INCREMENT ,
`ip` varchar(20) NOT NULL ,
`name` varchar(30)  NOT NULL ,
`url` varchar(30)  NOT NULL ,
`message` varchar(50)  NOT NULL ,
`date` date  NOT NULL ,
PRIMARY KEY ( `id` ) );

but when i want to insert into it some values using following command :

insert into shoutbox values(1, 6546556, sam, something.com,skdsd,23-02-07);

I get the following error:

error 1054(42s22): unkown colum 'sam' in 'field list'

ps. i am using mysql 5.0

thanks

Hi, are you aware of syntax for INSERT statement? anyways,1. the first thing you need learn is syntax for INSERT statement.
Syntax 1 =>

INSERT INTO TABLE table_name values(value1, value2...)

If you using the above syntax, make sure you provide, all values to all fields in the table and the values should in the order as that of field in the table.

for eg: if a table is like,

create table TEST
( 
column1 int,
column2 varchar(10)
)


then the insert statement for this looks like

insert into TEST values(1, 'apple')
insert into TEST values(2, 'strawbery')


Syntax 2 =>

INSERT INTO TABLE table_name (column1, column3, column8) values(value1, value3, value8)


can observe the flexibility in the second syntax? i.e you can insert values into only those columns for which know values. Make sure, you provide the values in order as that of the column name you specify.

NOTE:
Whenever you are using the syntax 2, make sure you will insert values for PRIMARY KEY and/or fields which are NOT NULL.2. fields which expects string or of char type, provide values in quotes.

so your insert statement will now become,

insert into shoutbox(id, ip, name, url, message, date) values(1, '6546556', 'sam', 'something.com', 'skdsd', '23-02-07');

or

insert into shoutbox values (1, '6546556', 'sam', 'something.com', 'skdsd', '23-02-07');

kath.

katharnakh
Posting Whiz in Training
237 posts since Jan 2006
Reputation Points: 19
Solved Threads: 34
 
insert into dns_soa   
	(
		sys_userid, 
		sys_groupid, 
		sys_perm_user, 
		sys_perm_group, 
		sys_perm_other, 
		server_id, 
		origin, 
		ns, 
		mbox, 
		serial,
		active,
		xfer
	) 
select 
		1,
		0,
		'riud',
		'riud',
		'',
		1,
		domain,
		concat('ns1.',domain),
		concat( substring ( domain, 1, LOCATE( '.', domain)    			– 1 ), '.', domain),  
		2010090201, 
		'Y', 
		'' 
from domains.dm_domains;
habeebuddincse
Newbie Poster
1 post since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You