Jump to content

SQL Syntax


Unholy Prayer

Recommended Posts

I can't figure out what's wrong the my SELECT sql syntax.  I'm trying to select an event from a table for the date being displayed.  This is my code:

$events = mysql_query("SELECT * FROM vbb_events WHERE date = $monthname $counter, $thisyear") or die("Error: ".mysql_error());

 

Any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/47123-sql-syntax/
Share on other sites

There is information we need according to the query you posted:

SELECT * FROM vbb_events WHERE date = $monthname $counter, $thisyear

 

There are 3 variables there in use. What do they all contain? Have you tried echoing out the query itself before you run it to make sure it contains what you think it does? If you post the actual content of the query, we may be able to help you a little more accurately.

Link to comment
https://forums.phpfreaks.com/topic/47123-sql-syntax/#findComment-229785
Share on other sites

Ah, I see it

 

You need quotes around date value

 

$events = mysql_query("SELECT * FROM vbb_events WHERE date = '$monthname $counter, $thisyear' ") or die("Error: ".mysql_error());

 

BTW, that's terrible way to store dates. You can't sort by it, you can't compare dates, you can't select ranges and you can't use the whole host of date/time functions provided. Use DATE or DATETIME types for dates - that's what they are there for.

Link to comment
https://forums.phpfreaks.com/topic/47123-sql-syntax/#findComment-229839
Share on other sites

Archived

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

×
×
  • Create New...

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.