Results 1 to 4 of 4

Thread: MySQL PHP Error for 'month'

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MySQL PHP Error for 'month'

    I have the following code and for some reason I keep getting "Error, Query failed"... Any ideas?

    PHP Code:
    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'); 

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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.
    - Mike

  3. #3
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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.
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •