EriRyoutan Posted August 7, 2006 Share Posted August 7, 2006 :-\ 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. ^^ Quote Link to comment https://forums.phpfreaks.com/topic/16823-select-from-date-field-error/ Share on other sites More sharing options...
fenway Posted August 7, 2006 Share Posted August 7, 2006 Well, the 3rd from the end is should be valid (though the trailing semi-colon is undesired), and shouldn't produce any error message. Quote Link to comment https://forums.phpfreaks.com/topic/16823-select-from-date-field-error/#findComment-70875 Share on other sites More sharing options...
EriRyoutan Posted August 8, 2006 Author Share Posted August 8, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/16823-select-from-date-field-error/#findComment-70941 Share on other sites More sharing options...
fenway Posted August 8, 2006 Share Posted August 8, 2006 I assume your table isn't called "table"? Quote Link to comment https://forums.phpfreaks.com/topic/16823-select-from-date-field-error/#findComment-70954 Share on other sites More sharing options...
EriRyoutan Posted August 8, 2006 Author Share Posted August 8, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/16823-select-from-date-field-error/#findComment-70960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.