Hi, I have a problem which relates to search a MySQL database, using PHP, searching for records between two dates. The search script is as follows: <form name="sample" action="search.php"> <input name="start" type="text" value="" size="15"> <a href="javascript://" onClick="getCalendarFor(document.sample.start)"><img src="img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> </input> From <input name="end" type="text" value="" size="15"> <a href="javascript://" onClick="getCalendarFor(document.sample.end)"><img src="img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> </input> To <input type="submit" name="Submit" value="Submit"> This works fine and javascript pop up window displays the date when the visitor chooses a date. The search script is as follows: $result = mysql_query("select * from table WHERE date BETWEEN '".$_POST['start']."' and '".$_POST['end']."' ") or die(mysql_error()); The problem I have is the search script doesn't find any records between the two dates - even though I know they exist. The dates are stored in the MySQL database in a date type field. Is there something I am missing to search between two dates, or is the pop up calender causing the issue (looking at the form output it does output the dates to mm-dd-yyyy as stored in the MySQL database). Thanks, CC
output from form may change. please try to write (echo) the form output to a blank page to see what is going from form. if you see different mm-dd-yyyy format, you must edit the date type
Thanks for the reply but I can see the form postings from the address bar on the search script page and the format is mm-dd-yyyy (exactly as stored in the MySQL database)
If you see the variables in the address bar then you are using a GET request but your script is using POST. You didnt specify which Change it so they match <form name="sample" method="POST" action="search.php"> or change the script to GET and see if that helps. $result = mysql_query("select * from table WHERE date BETWEEN '".$_GET['start']."' and '".$_GET['end']."' ") or die(mysql_error());
IMHO, in the mysql where clause, the date should be in the format 'yyyy-mm-dd' I quote from the mysql help file: You can create $startdate as: $startdate = substr($_GET['start'],0,4)) . "-" . substr($_GET['start'],5,2)) . "-" . substr($_GET['start'],8,2)) and use this in where clause.