I have six dropdown menus for selecting two dates I have the folowing code, which give me no results no matter which date i choose
$year1 = $_POST['year1'];
$month1 = $_POST['month1'];
$day1 = $_POST['day1'];
$date1 = $year1 . "/" . $month1 . "/" . $day1;
$year2 = $_POST['year2'];
$month2 = $_POST['month2'];
$day2 = $_POST['day2'];
$date2 = $year2 . "/" . $month2 . "/" . $day2;
$result = mysql_query("SELECT * FROM services WHERE date between '%" . $date1 . "%' AND '%" . $date2 . "%' ORDER BY id " );
but if I replace variables $date1 and $date2 in last line with specific date i get the right result.
$result = mysql_query("SELECT * FROM services WHERE date between '2012/10/01' AND '2012/11/12' ORDER BY id " );
Can anyone tell what it wrong with variable $date1 and $date2?
you need to remove the %
symbols from your query and just use
$result = mysql_query("SELECT * FROM services WHERE date between '" . $date1 . "' AND '" . $date2 . "' ORDER BY id " );
% is using for wild card search... you have to remove it from your code...
$sql = "SELECT * FROM services WHERE date between '" . $date1 . "' AND '" . $date2 . "' ORDER BY id ";
mysql_query($sql);