jeff5656 Posted November 20, 2008 Share Posted November 20, 2008 In my database table I have a variable called which_month. The values are November, December, etc. I want the following code to pull the record with with the current month, but when I run this code I get: "Invalid query: Unknown column 'November' in 'where clause'" <?php include ("../connectdb.php"); $curr_month = date (F); $consultsq1 = "SELECT * FROM `staffsched` WHERE `which_month` = $curr_month"; $result = mysql_query ($consultsq1) or die ("Invalid query: " . mysql_error ()); $row = mysql_fetch_array ($result); ?> Link to comment https://forums.phpfreaks.com/topic/133553-solved-unknown-column-in-where-clause/ Share on other sites More sharing options...
marcus Posted November 20, 2008 Share Posted November 20, 2008 $consultsql = "SELECT * FROM `staffsched` WHERE `which_month`='".$curr_month."'"; Link to comment https://forums.phpfreaks.com/topic/133553-solved-unknown-column-in-where-clause/#findComment-694673 Share on other sites More sharing options...
revraz Posted November 20, 2008 Share Posted November 20, 2008 Means you forgot single quotes around the $curr_month variable. Link to comment https://forums.phpfreaks.com/topic/133553-solved-unknown-column-in-where-clause/#findComment-694682 Share on other sites More sharing options...
marcus Posted November 20, 2008 Share Posted November 20, 2008 What revraz said It's common to forget quotes, just use them when you can to escape information, makes error checking a lot easier Link to comment https://forums.phpfreaks.com/topic/133553-solved-unknown-column-in-where-clause/#findComment-694684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.