Hey guys i have two date inputs containing three dropboxes for day,month and year each.
day has a name d1, month=m2,year=y1 and similarly for the second date input its d2,m2 and y2
i’m trying to query the database for information between a particular date range.
$date1=date("Y-m-d", mktime(0, 0, 0, $_POST['m1'], $_POST['d1'],$_POST['y1']));
$date2=date("Y-m-d", mktime(0, 0, 0, $_POST['m2'], $_POST['d2'],$_POST['y2']));
echo $date1." and ".$date2;
$query="SELECT *FROM FDB where time BETWEEN ".$date1." and ".$date2;
$f = mysql_query($query) or die(mysql_error());
$nfiles= mysql_num_rows($f);
$query="SELECT *FROM usr where created BETWEEN ".$date1." and ".$date2;
$f = mysql_query($query) or die(mysql_error());
$nus= mysql_num_rows($f);
It is showing an error on the line below
$query="SELECT *FROM history WHERE ACTIVITY='Logged In' where CAST(FLOOR(CAST(time AS FLOAT))AS DATETIME) between ".$date1." AND ".$date2;
The error is
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where CAST(FLOOR(CAST(time AS FLOAT))AS DATETIME) between `2011-01-01` AND `2012' at line 1
How do I need to change my code so that I don’t get the error any longer?
You got 2 WHERE clauses on your code.
Try this way