<?php
include "../../config/master.php";

$id=$_POST['id'];

$title=$_POST['title'];
$desc=$_POST['description'];
$order=$_POST['display_order'];

$data=mysqli_fetch_assoc(mysqli_query($conn,"SELECT * FROM village_sliders WHERE id='$id'"));
$image=$data['image'];

if(isset($_FILES['image']) && $_FILES['image']['error']==0){

$dir="../../uploads/sliders/";

$ext=pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION);

$image="slider_".time().rand(100,999).".".$ext;

move_uploaded_file($_FILES['image']['tmp_name'],$dir.$image);

if(!empty($data['image'])){
$file=$dir.$data['image'];
if(file_exists($file)) unlink($file);
}
}

mysqli_query($conn,"
UPDATE village_sliders SET
title='$title',
description='$desc',
display_order='$order',
image='$image'
WHERE id='$id'
");

echo json_encode(["status"=>"success"]);