SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mysql form date query help

    php mysql form date query help

    hello all-

    I am trying to do a mysql database lookup by passing a begin date and end date from an html form. I have a date column in my database which is written to using the php function date("Y-m-d"); The date column is currently formatted as a mysql DATE field. The goal is to allow the user to lookup customer rows based between a begin and end date.

    Here is my string, which fails:

    $query='select * from '.$table.' where Date between `'.$Begin_Date.'` and `'.$End_Date.'` ';

    echo mysql_error();

    the error message returns:

    Unknown column '2010-09-03' in 'where clause'


    Any help would be much appreciated - I need to get this project done!

    Much Thanks!

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't put your dates in backticks, it thinks that it is referencing a column, which it isn't.

  3. #3
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the solution and this code works:

    $query="select * from ".$table." where `Date` between '".$Begin_Date."' and '".$End_Date."' ";

    Thanks Guys!


Tags for this Thread

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
  •