<?php
require_once('header.php');
require_once('check_user.php');


$category_id = intval($_GET['category_id']);
$msg_id = intval($_GET['msg_id']);

$sql   = "SELECT * FROM {$tablepre}favorites where msg_id=".$msg_id." and scuser_id=".$_SESSION["uid"]." limit 0,1";
$myrow = $db->get_row($sql);

if (empty($myrow)){
   $sql="insert into {$tablepre}favorites (scuser_id,msg_id) values('".$_SESSION["uid"]."','".$msg_id."')";
   $db->exec($sql);
   $sql="update {$tablepre}categorymng set fav_num=fav_num+1 where msg_id='".$msg_id."'";
   $db->exec($sql);
   $status=1;
}else{
   $status=2;
}

$response_arr = array("status" => $status,"msg_id"  => $msg_id,"category_id"  => $category_id);
echo json_encode($response_arr);
exit;
?>