<?php
include("db.php");
$connect = $conn;
if(isset($_POST['submit'])){
  $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'];
  $date = date("Y-m-d");
  $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;
}
}

?>



<form action="form-test.php" method="POST">
  <h1><?php echo date("Y-m-d")?></h1>
  <input type="hidden" name="date" value="<?php echo date("Y-m-d")?>">
  <input type="text" name="username" placeholder="username"><br>
  <input type="text" name="car" placeholder="car"><br>
  <input type="text" name="client" placeholder="client"><br>
  <input type="number" name="job" placeholder="job"><br>
  <input type="text" name="description" placeholder="description"><br>
  <input type="text" name="destination" placeholder="destination"><br>
  <p>Start Time</p><br>
  <input type="time" name="start_time"><br>
  <p>End Time</p><br>
  <input type="time" name="end_time"><br>
  <p>Start Time 2</p><br>
  <input type="time" name="start_time2"><br>
  <p>End Time 2</p><br>
  <input type="time" name="end_time2"><br>
  <input type="number" name="start_mileage" placeholder="start mileage"><br>
  <input type="number" name="end_mileage" placeholder="end mileage"><br>
<input type="number" name="station_mileage" value=" " placeholder="station mileage"><br>
  <input type="tel" name="amount" value=" " placeholder="amount"><br>
  <input type="tel" name="litres" value= " " placeholder="litres"><br>
  <input type="hidden" name="expense_account"><br>


  <input type="submit" name="submit">

</form>
