I have been trying to compare two dates in a query, the code goes like this
WHERE Reservation.InDate >= ".$_POST['dateSince']."
AND (Reservation.ResStatus = 'Occupied' OR Reservation.ResStatus = 'Vacant')";
The query is working fine but it does not take the date condition into consideration, I have tried casting the two dates, I tried swapping the conditions, I tried other approaches but it seems that I am doing something wrong with the dates.
I have echoed $_POST['dateSince'] and the page does echo the date selected indeed. I would appreciate any hints.
this:
".$_POST['dateSince']."
should be surrounded by
''
like this
'".$_POST['dateSince']."'
and you should sanitize your variables to protect yourself against sql injection, if you're using mysql
WHERE Reservation.InDate >= '".mysql_real_escape_string($_POST['dateSince'])."'
AND (Reservation.ResStatus = 'Occupied' OR Reservation.ResStatus = 'Vacant')";
if you're using mysqli
WHERE Reservation.InDate >= '".mysqli_real_escape_string($link, $_POST['dateSince'])."'
AND (Reservation.ResStatus = 'Occupied' OR Reservation.ResStatus = 'Vacant')";
Note: better look into mysqli or PDO prepared statements...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.