Unholy Prayer Posted April 15, 2007 Share Posted April 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted April 15, 2007 Share Posted April 15, 2007 If the date column is a date or date time column the date needs to be in the form yyyy-mm-dd or yyyy-mm-dd hh:mm:ss. Also I think date might be a reserved word in MySQL, so use back ticks: $events = mysql_query("SELECT * FROM vbb_events WHERE `date` = ... Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted April 15, 2007 Author Share Posted April 15, 2007 Well the date column is a varchar field. I tried changing the "date" column to "edate" and it still doesn't work. Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 15, 2007 Share Posted April 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted April 15, 2007 Author Share Posted April 15, 2007 well the error that is displayed is Error: Unknown column 'April 1, 2007' in 'where clause' so I know the variables are right. It's supposed to display the events for the date being displayed on a calendar. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 15, 2007 Share Posted April 15, 2007 As Obsidian requested $sql = "SELECT * FROM vbb_events WHERE date = $monthname $counter, $thisyear"; echo $sql; What is the output from that? Quote Link to comment Share on other sites More sharing options...
Barand Posted April 15, 2007 Share Posted April 15, 2007 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. Quote Link to comment 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.