Page 1 of 1

mysql: wont reconize a column

Posted: Sun Jan 19, 2003 11:33 pm
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!

Posted: Mon Jan 20, 2003 8:20 am
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.

Posted: Mon Jan 20, 2003 2:19 pm
by puckeye
Or better yet use single quotes around your field names.

Posted: Mon Jan 20, 2003 6:40 pm
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.

Posted: Mon Jan 20, 2003 6:43 pm
by Sevengraff
sweet, that worked. thanks people!

Posted: Tue Jan 21, 2003 2:22 am
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

Posted: Tue Jan 21, 2003 10:30 pm
by Sevengraff
ohh, thats what those are called... backticks....