MNSarahG Posted March 7, 2008 Share Posted March 7, 2008 Hi, I'm trying to get this SQLi query to return entries that have the current month as their value in my database's "annMonth" field. The idea is that it returns a list of employees who have an anniversary in the current month. I'm having issues with (I think) my syntax, and a few hours of experimenting has yielded nothing. When I manually replace the variable in the WHERE clause with a "3" (instead of '$currDate;') it works fine. My code: $currDate = date("m"); /* Send a query to the server */ if ($result = mysqli_query($link, ' SELECT firstName, lastName, annMonth, annDay, annYear FROM employees WHERE annMonth = '$currDate;' ORDER BY annDay')) { Thanks in advance for any help! - Sarah - Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 7, 2008 Share Posted March 7, 2008 Hi there. Your single quotes around the variable are breaking the query, since it's surrounded by single quotes itself. Use double quotes (") for the query: $currDate = date("m"); /* Send a query to the server */ if ($result = mysqli_query($link, " SELECT firstName, lastName, annMonth, annDay, annYear FROM employees WHERE annMonth = '$currDate;' ORDER BY annDay")) { Quote Link to comment Share on other sites More sharing options...
MNSarahG Posted March 7, 2008 Author Share Posted March 7, 2008 BRILLIANT. And so simple. Thank you!! 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.