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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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