PDA

View Full Version : MySQL PHP Error for 'month'



tomyknoker
04-15-2007, 11:39 AM
I have the following code and for some reason I keep getting "Error, Query failed"... Any ideas?



if($_GET['month']=="1") {
$month = '1';
}
elseif($_GET['month']=="2") {
$month = '2';
}
elseif($_GET['month']=="3") {
$month = '3';
}

//birthday search
$query = mysql_query("SELECT * FROM `tblmembers` WHERE (MONTH(DateOfBirth) = '{$month}') AND `MemberApproved`='A'");
$result = mysql_query($query) or die('Error, query failed');

mburt
04-15-2007, 11:45 AM
and for some reason I keep getting "Error, Query failed"... Any ideas?
Well you specified the "or die()" function to write "Error, query failed" if the program couldn't respond to the query.

The only problem I see is the AND keyword outside of the original statement, I'm not sure you can put that inside WHERE. Everything else looks fine, unless the data itself doesn't exist in your database.

tomyknoker
04-15-2007, 11:48 AM
So is there a better way I can re-write it? The data is definitely there... Do I need to make 'MONTH' all in capitals in the if statements?

mburt
04-15-2007, 11:52 AM
Now that you mention it, I don't think MONTH should be in capitals at all. I would try to test something out normally, but where it's your database, I can't (obviously). You'll have to mess with it a bit.