<?php
 include('database/connection.php');
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
// echo "<pre>";
// print_r($_POST);
// die;
$packeg_name  = $_POST['package_name'];
$price        = $_POST['price'];
$old_price    = $_POST['old_price'];
$category_id  = $_POST['category_id'];
$descriptions = $_POST['descriptions'];
$slug = preg_replace('/[^A-Za-z0-9-]+/', '-', $packeg_name);
//  die;
// Attempt insert query execution
if($_POST['id'])
{ 
   $id = $_POST['id'];
   echo $sql = "UPDATE packages SET package_name = '".$packeg_name."', price = '".$price."' , old_price = '".$old_price."' ,descriptions = '".$descriptions."',category_id = ".$category_id." Where id = ".$id;
}else{
    $sql = "INSERT INTO packages (package_name, price, old_price,descriptions,slug,category_id) VALUES ('".$packeg_name."', '".$price."','".$old_price."','".$descriptions."','".$slug."',".$category_id.")";
}

if(mysqli_query($link, $sql)){
    // return 1;
    echo  1;
} else{
    // echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
    return false;
}
 
// Close connection
mysqli_close($link);
?>