I definitely regret asking such a simple question, but it's been driving me off the wall, and I'm not sure if it's because of an update or anything. But can anyone tell me what the error with the following SQL statement is?
$iname = mysql_query("SELECT * FROM calendarevents WHERE 'EventMonth'="January" AND 'EventDay'="1"")
or die(mysql_error());
This should work better, using correct quotes and backticks, please have a look at the query
$iname = mysql_query("SELECT * FROM calendarevents WHERE `EventMonth`= 'January' AND `EventDay`= 1 ")
SIDENOTE:
Please consider using PDO or mysqli_ instead of mysql_* functions.
This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Use the following:
$iname = mysql_query("SELECT * FROM calendarevents WHERE
EventMonth='January' AND
EventDay='1'") or die(mysql_error());
The way that you have used double quotes (") is the first and the biggest of issues, and you should use backticks(`) instead of single quotes(') for escaping table and column names in mysql.
you cannot use double quotes ["] inside of a sql statement.
january and 1 need to be in single quotes instead of double.
You also don't need quotes around the field names.
"SELECT * FROM calendarevents WHERE 'EventMonth'="January" AND 'EventDay'="1""
should be
"SELECT * FROM calendarevents WHERE EventMonth='Januay' AND EventDay='1'"
$iname = mysql_query("SELECT * FROM `calendarevents` WHERE `EventMonth`="January" AND `EventDay`=1")
or die(mysql_error());
Try this:
$query = "SELECT * FROM calendarevents WHERE EventMonth='January' AND EventDay = '1'";
$iname = mysql_query($query);