i'm learning php at the moment and i wanted to make a car hire system to challenge myself a bit.
Now i am stuck with a validation question, i got 5 diffrent cars and want to check if the car is available at the dates the user submitted.
my database table got a startdate, enddate, car and a id
This is what i'm trying to get working:
if($_POST){
$date1 = $_POST["startdate"];
$date2 = $_POST["enddate"];
$car= $_POST["car"];
$qry1 = "SELECT * FROM hire WHERE startdate between '{$date1}' and '{$date2}'
UNION
SELECT * FROM hire WHERE enddate between '{$date1}' and '{$date2}'";
$qry2 = "SELECT * from hire WHERE car = '{$car}'";
$results = mysql_query($qry1, $bd);
$results2 = mysql_query($qry2, $bd);
$row = mysql_num_rows($results);
$row2 = mysql_num_rows($results2);
if ($row && $row2 > 1 ){
die("it twerks");
}
else {
//do stuff\
}
}
now it says its always available.
EDIT
start and enddate are DATE fields format is Y-m-d.