<?php
include("db.php");
$connect = $conn;
if(isset($_POST['submit'])){
  $date = $_POST['date'];
  $username = $_POST['username'];
  $car = $_POST['car'];
  $client = $_POST['client'];
  $job = $_POST['job'];
  $description = $_POST['description'];
  $destination = $_POST['destination'];
  $starttime = $_POST['start_time'];
  $endtime = $_POST['end_time'];
  $starttime2 = $_POST['start_time2'];
  $endtime2 = $_POST['end_time2'];
  $startmileage = $_POST['start_mileage'];
  $endmileage = $_POST['end_mileage'];
  $station = $_POST['station_mileage'];
  $stationmileage = $_POST['station_mileage'];
  $amount = $_POST['amount'];
  $litres = $_POST['litres'];
  $expense = $_POST['expense_account'];
  $empty = '';
  $empty2 = ' 0 ';
  $empty3 = '';
  $empty4 = '';
  $empty5 = '';

  if($stationmileage > 0){
    $result = "INSERT INTO trips(username,car,client,job,description,destination,date,start_time,end_time,start_time2,end_time2,start_mileage,end_mileage,station_mileage,amount,litres,expense_account)
    VALUES('$username','$car','$client','$job','$description','$destination','$date','$starttime','$endtime','$starttime2','$endtime2','$startmileage','$stationmileage','$station','$amount','$litres','$empty');";
    $result2= "INSERT INTO trips(username,car,client,job,description,destination,date,start_time,end_time,start_time2,end_time2,start_mileage,end_mileage,station_mileage,amount,litres,expense_account)
    VALUES('$username','$car','$client','$job','$description','$destination','$date','$starttime','$endtime','$starttime2','$endtime2','$stationmileage','$endmileage','$empty2','$empty3','$empty4','$empty5');";
    if ($conn->multi_query($result) === TRUE) {
    echo "Success";
}else{
    echo "Error: " . $result . "<br>" . $conn->error;
}
echo "<br>";
if ($conn->multi_query($result2) === TRUE) {
echo "Success";
} else {
echo "Error: " . $result2 . "<br>" . $conn->error;
}

  }else{
    $result3 = "INSERT INTO trips(username,car,client,job,description,destination,date,start_time,end_time,start_time2,end_time2,start_mileage,end_mileage,station_mileage,amount,litres,expense_account)
    VALUES('$username','$car','$client','$job','$description','$destination','$date','$starttime','$endtime','$starttime2','$endtime2','$startmileage','$endmileage','$empty2','$empty3','$empty4','$empty5');";
  }
  echo "<br>";
  if ($conn->multi_query($result3) === TRUE) {
  echo "Success";
} else {
  echo "Error: " . $result3 . "<br>" . $conn->error;
}
}

?>

<h1><?php echo $_POST['username']?></h1>
