<?php 
session_start();
include('../includes/dbcon.php');

$str=" ";

$br=0;

$cname= trim($_POST['cname']);
$address= trim($_POST['address']);
$tel= trim($_POST['tel']);
$email= trim($_POST['email']);
$web= trim($_POST['web']);
$br= trim($_POST['br']);
$edate=date("Y-m-d");
$userid=$_SESSION['officesync_id'];
$scode= trim($_POST['scode']);

if (empty($br)){ $br=0;  }  

if (empty($scode)){ $scode='0';  }  


//echo $br;


if (empty($cname)){
	//echo "<script type='text/javascript'>alert('Company Name is mandatory');</script>";
	//echo "<script>document.location='admin_company.php'</script>"; 
}

else {  ////else part
		if (empty($address)){
		//	echo "<script type='text/javascript'>alert('Address is mandatory!');</script>";
			//echo "<script>document.location='admin_company.php'</script>"; 
		}

		else { ///else of if (empty($address)){

////////  data save ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if ($scode<>0){
$dbval="select * from company_master where cost_name='$cname' or cost_sname='$scode'   " ;

}
else {

$dbval="select * from company_master where cost_name='$cname'"	;

}


$query=mysqli_query($con,$dbval)or die(mysqli_error($con));
    $count=mysqli_num_rows($query);
if ($count>0)
{
	echo "<script type='text/javascript'>alert('Exsisting Company!');</script>";
	echo "<script>document.location='admin_company.php'</script>"; 
}

else {



$pp="INSERT INTO company_master(cost_name,address,telephone,email,web,cost_active,br,cost_sname) 
			  VALUES('$cname','$address','$tel','$email','$web',1,$br,'$scode')  ";
			  echo $pp;


if ( mysqli_query($con,"INSERT INTO company_master(cost_name,address,telephone,email,web,cost_active,br,cost_sname) 
			  VALUES('$cname','$address','$tel','$email','$web',1,'$br','$scode')  ")or die(mysqli_error($con)))
	        {
					
				echo "<script type='text/javascript'>alert('Successfully added !');</script>";
				echo "<script>document.location='admin_company.php'</script>"; 
	     	 
			}
}		
///////  End of data save part  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		}  //// end of  else of if (empty($address)){	
}  /////    end of else {  ////else part











?>

