data NOT being inserted into SQL table

Questions about programming languages and debugging
Post Reply
User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

data NOT being inserted into SQL table

Post by Swan »

For some odd reason...the second line (the suck-o mug one) doesnt get added to the table.

http://code.suck-o.com/97

The above link is the relevant table. (I extracted the table and omitted the rest of the code which is working perfect to save your eyes.)

The curious thing is, the first value is entered, the second one isnt.

For the first link, I put the relevant line in @@ to make it easier to spot :)

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

I need more info...

Where is the "suck-o mug" thingy? And is it values that aren't being entered, or is it the whole table column?
"The best place to hide a tree, is in a forest"

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »


User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

hm, are you sure you don't have to use ` for the names?

I looked at one of my db dumps and it looks like this:

Code: Select all

DROP TABLE IF EXISTS `test1`;
CREATE TABLE `test1` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL default '',
  `dedication` varchar(100) NOT NULL default '',
  `body` text NOT NULL,
  PRIMARY KEY  (`id`)
) 
:-k

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »

BB I dont think so....

the tables HAVE been created ok....

see the first line, the one about the sucko thsirt has been added no problem....its the second one, the line about the sucko mug that doesnt work.

:?

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

um, what are those @ about in line 7? they don't appear in the mysql reference for INSERTs using VALUES:

Code: Select all

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »

the @@ was used to make it clear which line was the relevant one.

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

ah, ok...^^

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

hm, shouldn't you better declare the table columns like here:
http://code.suck-o.com/99

at least that's how it is shown in the reference... :-k

edit: meh, nvm...should work without it as long as you give values to all columns...

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »

Ok...so I went into mysql Adminstrator, dropped the table and ran the code again, with ALL the values added. It seems that the code is "run once", currently, it seems that I cannot update the values, I have to drop the table and then run the code again in order to be able to add any new values.

That is rather bothersome...is there some way to overcome this?

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

alrighty, works for me now, 2 errors:
- a typo in the "mug" query, check the comma in "c":

Code: Select all

('00002', 'suck-o mug!', 'a','b','c,','d')
but that's not the main error.

- you have 5 columns:
product_id
product_name
product_description
product_price
product_quantity
but you try to submit 6 values in each query, remove the 6th value ('d') in both queries... :wink:

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »

resolved. Thanks BB. :D

Will post the source code for it when Im done.

Post Reply