mysql: wont reconize a column

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

mysql: wont reconize a column

Post by Sevengraff »

Here is the table structure:

Code: Select all

CREATE TABLE `news comments` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`parent` INT NOT NULL ,
`author` VARCHAR( 60 ) NOT NULL ,
`date` DATE NOT NULL ,
`comment` TEXT NOT NULL 
);
and there are several entries, all using every filed. but when i use this query in PHP and phpMyAdmn:

SELECT * FROM news comments WHERE parent='$id' ORDER BY date ASC

i get the error: Unknown column 'parent' in 'where clause'

Why is it giving me this error? I can insert data into this column without any problems. but selecting stuff i get this error. it doesn't make sense!
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Might it have something to do with the space in the table name? It seems like the "FROM news comments" statement would be interpreted as the table "FROM news AS comments" and so would be looking for the table "news". Try renaming the table to news_comments and see if that helps.
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Or better yet use single quotes around your field names.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

i did try putting a quote around the name, but i got this:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''news comments' WHERE parent='5' ORDER BY date ASC' at line 1

so i'll try re-naming it. wont be that hard.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

sweet, that worked. thanks people!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You don't put single quotes around the table or field names, instead you would use backticks (` instead of ') - on my keyboard that's the key next to the 1 key at the far left of the board.

However, not having spaces in table names is a much better solution.

Mac
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

ohh, thats what those are called... backticks....
Post Reply