<?php include("../cn.php");
$id = $_REQUEST["carid"];

$carname = $_REQUEST["title"];
$model = $_REQUEST["model"];
$plate = $_REQUEST["plate"];
// $brand = filter_input(INPUT_POST, 'brand', FILTER_SANITIZE_STRING);
$brand = $_REQUEST["brand"];
$dailyrate = $_REQUEST["rate"];
$ratepermin = $_REQUEST["ratePerMin"];
$availability = "yes";

$img_name = date("Ymdis");

$photo=($_FILES["photo"]["name"]!="")?"cars/car_".$img_name.".".pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION):"";
if($_FILES["photo"]["name"]!="")
{
    move_uploaded_file($_FILES["photo"]["tmp_name"],"../".$photo);
	$imgsql = "car_img='$photo',";

}

/*$img_name = date("Ymdis");

$photo=($_FILES["photo"]["name"]!="")?"assets/img/cars/cars_".$img_name.".".pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION):"";
if($_FILES["photo"]["name"]!="")
{
    move_uploaded_file($_FILES["photo"]["tmp_name"],"/booking/".$photo);
	$imgsql = "`car_img`='$photo',";

}*/

$query="UPDATE `cars` SET $imgsql `car_name`='$carname', `car_nameplate`='$plate', `model`='$model',
`brand` = '$brand', `ac_price_per_day`='$dailyrate', `ac_price`='$ratepermin', 
`car_availability`='$availability' WHERE `car_id`='$id'";

$myfile = fopen("testfile.txt", "w");
fwrite($myfile, $query);
fclose($myfile);

// echo $query;

mysqli_query($connect, $query);

header("location:../cars.php");

?>