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 - Link to comment https://forums.phpfreaks.com/topic/94970-php-variable-in-a-mysqli-query/ 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")) { Link to comment https://forums.phpfreaks.com/topic/94970-php-variable-in-a-mysqli-query/#findComment-486470 Share on other sites More sharing options...
MNSarahG Posted March 7, 2008 Author Share Posted March 7, 2008 BRILLIANT. And so simple. Thank you!! Link to comment https://forums.phpfreaks.com/topic/94970-php-variable-in-a-mysqli-query/#findComment-486473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.