User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 391,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,624 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1736 | Replies: 2
Reply
Join Date: Nov 2004
Posts: 229
Reputation: sam1 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

insert statement error

  #1  
Mar 14th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Posts: 176
Reputation: vssp is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
vssp vssp is offline Offline
Junior Poster

Re: insert statement error

  #2  
Mar 15th, 2007
6 fields in your table but u inert only 5 values
char must be single quote
Thanks
VSSP
Reply With Quote  
Join Date: Jan 2006
Posts: 215
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 19
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: insert statement error

  #3  
Mar 16th, 2007
Originally Posted by sam1 View Post
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.
Last edited by katharnakh : Mar 16th, 2007 at 3:00 am.
challenge the limits
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 9:30 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC