Jump to content

Archived

This topic is now archived and is closed to further replies.

EriRyoutan

select from date field error

Recommended Posts

:-\ for some reason, i can't get a select from a date field to work. it always pukes up with an error and says

[code]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 'WHERE day = 20060807' at line 1[/code]

... gee, thanks mr. error message...

anyway, here's a summary of what i've got... and i've got the errors actually trapped, it just takes up a lot of code room...
[code]mysql_query("CREATE TABLE table ( `id` INT NOT NULL AUTO_INCREMENT , `day` DATE, `stuff` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `id` ) ) TYPE = MYISAM;
//add fake data to table here...
//none of these work, though...
mysql_query("SELECT * FROM table WHERE day = 20060807;");
mysql_query("SELECT * FROM table WHERE day = '20060807';");
mysql_query("SELECT * FROM table WHERE `day` = '20060807';");
mysql_query("SELECT * FROM table WHERE day = 2006-08-07;");
mysql_query("SELECT * FROM table WHERE `day` = '2006-08-07';");
mysql_query("SELECT * FROM table WHERE `day` = '06-08-07';");
mysql_query("SELECT stuff FROM table WHERE day = 20060807;");[/code]

... glurgh... any ideas?

thank you for reading this, by the way. ^^

Share this post


Link to post
Share on other sites
Well, the 3rd from the end is should be valid (though the trailing semi-colon is undesired), and shouldn't produce any error message.

Share this post


Link to post
Share on other sites
That's the first one I tried, actually, before i started messing with the syntax. It still pukes with the same error,
[code]...check syntax near 'WHERE `day` =  '2006-08-07'' at line 1[/code]

Share this post


Link to post
Share on other sites
I assume your table isn't called "table"?

Share this post


Link to post
Share on other sites
byeh... i figured it out, and it wasn't a problem with the syntax. lets just say i was stupid, and didn't know how to program php.

(i had the bright idea of making a query() function to do mysql_query with the or die() every time, but the problem was that i coded -that- wrong, so... yeah. )

note to others: make sure the problem is the one it tells you to look at...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.