<?php
include 'include/db.php';
include 'include/connect.php';
$id = $_POST['id'];
$todays = date("Y-m-d");

if(!empty($id) && $_POST['name'] != "0"){

                $data['blog_name'] = $_POST['name'];
                $data['blog_cat'] = $_POST['cat'];
                $data['blog_content'] = $_POST['card'];
                $data['blog_title'] = $_POST['text_blog'];
                $data['date'] = $todays;
                $data['blog_img'] = $_POST['blog_img'];
                $data['blog_status'] = $_POST['blog_status'];
                $data['blog_country'] = $_POST['blog_country'];
                
		$rs = $db->update('tb_blog',$data,'blog_id',$id);
           if($rs){
            echo "0";
           } else {
            echo "00";
           }

     } else {

      if($_POST['name'] != "0") {
           
      $rs = $db->insert('tb_blog',array(
       'blog_name' => $_POST['name'],
       'blog_cat' => $_POST['cat'],
       'blog_content' => $_POST['card'],
       'blog_title' => $_POST['text_blog'],
       'blog_img' => $_POST['blog_img'],
       'date' => $todays
            ));

           if($rs){
            echo "2";
           } else {
            echo "0";
           }
         } else {
            echo "3";
        }
}
?>

