So I have this weird problem: below you can see my php code:
if($type == "kilometers") {
$sql = "SELECT * FROM transports WHERE user='".$user."' AND (theDate BETWEEN '".$fromDateFormatted."' AND '".$toDateFormatted."')";
$status = mysqli_query($conn, $sql);
if(!$status) {
$result = $conn->error;
die($result);
}
$num_rows = mysqli_num_rows($status);
for($i = 0; $i < $num_rows; $i++) {
$data = mysqli_fetch_assoc($status);
$results[$i] = $data;
$date = strtotime($data["theDate"]);
$date = date("d/m/Y", $date);
$results[$i]["formattedDate"] = $date;
}
}else if($type == "vacation") {
$sql = "SELECT * FROM leave";
$status = mysqli_query($conn, $sql);
if(!$status) {
$result = $conn->error;
die($result);
}
$num_rows = mysqli_num_rows($status);
for($i = 0; $i < $num_rows; $i++) {
$data = mysqli_fetch_assoc($status);
$results[$i] = $data;
$fromDate = strtotime($data["fromDate"]);
$fromDate = date("d/m/Y", $fromDate);
$toDate = strtotime($data["toDate"]);
$toDate = date("d/m/Y", $toDate);
$results[$i]["formattedDate"] = $fromDate;
$results[$i]["formattedToDate"] = $toDate;
}
}
This code is initiated by an ajax call which posts the 'type' variable. With different types comes different information. The first 'kilometers' query returns no errors, but the second 'vacation' query gives me the following error:
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 'leave' at line 1
But as you can see in the following image, both tables are created. Any ideas?