Jump to content


Photo

select from date field error


  • Please log in to reply
4 replies to this topic

#1 EriRyoutan

EriRyoutan
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 07 August 2006 - 07:34 PM

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

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

... 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...
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;");

... glurgh... any ideas?

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

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 07 August 2006 - 10:58 PM

Well, the 3rd from the end is should be valid (though the trailing semi-colon is undesired), and shouldn't produce any error message.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 EriRyoutan

EriRyoutan
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 08 August 2006 - 03:26 AM

That's the first one I tried, actually, before i started messing with the syntax. It still pukes with the same error,
...check syntax near 'WHERE `day` =  '2006-08-07'' at line 1


#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 08 August 2006 - 04:36 AM

I assume your table isn't called "table"?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 EriRyoutan

EriRyoutan
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 08 August 2006 - 05:06 AM

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...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users