<?php
require_once 'config.php';
$error=false;
$errors=array();
$error=false;
$errors=array();


if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
	
	
	$fname=$_POST['category_name'];
	
	
	
	
	
	
	
	if(empty($fname)){
		$error=true;
		$errors['success']='Please enter Category Name';
	}
	
	
	$checkEmailExists=mysqli_query($con,"SELECT * FROM categories WHERE name='".$fname."'");
	
	if(mysqli_num_rows($checkEmailExists)>0){
		$error=true;
		$errors['fname']='Category already exists, Please try new one.';
	}
	
	
	if($error==false)
	{
		$createCustomer=mysqli_query($con,"INSERT INTO categories (name,status) VALUES('".$fname."',1)");
		if($createCustomer){
	     	$errors['success']='Category created Sucessfully';
	 }else{
	     $errors['success']='Somthing went wrong !!';
	 }
 	 
		
	}
	
	
	 	echo json_encode($errors);
}

?>
 