<?php
error_reporting(0);
@session_start();
include("config.php");
$branch=$_POST[branch];
$owner=$_POST[owner];
$address=$_POST[address];
$mob1=$_POST[mob1];
$mob2=$_POST[mob2];
$map=$_POST[map];


$flag = $_REQUEST[flag];
$mode = $_REQUEST[mode];

/***********************************/


    



$id= $_POST[id];
 if($id=="")
{ 
    	 $query_insert=sprintf("Insert INTO location SET branch='$branch',owner='%s',address='%s',mob1='%s',mob2='%s',mapurl='$map'",$owner,$address,$mob1,$mob2); 
		if(!($resi=mysql_query($query_insert))){echo $query_insert.mysql_error(); exit;}
		$id=mysql_insert_id();		
if($_FILES["mimg"]["name"]!="") 
		{
				 
			 $fileload = $_FILES["mimg"]["name"];
			
			 $file_ext = explode(".",$fileload);
			 $myattach="mimg_".$id.".".$file_ext[1];
			 
			$destpath=$uploadpath.$myattach;
				 
			$file1 = move_uploaded_file($_FILES["mimg"]["tmp_name"],$destpath); 
			 $updatecategory=sprintf("UPDATE location SET mimg ='%s' WHERE id ='%d'", $myattach, $id);
			if(!($result = mysql_query($updatecategory))){echo $updatecategory.mysql_error();exit;}
		}	
		
		header("Location:add-contact.php?flag=dn");
		exit;
}
if($id!="")
{
     $query_up=sprintf("UPDATE location SET 
		 branch='$branch',owner='%s',address='%s',mob1='%s',mob2='%s',mapurl='$map'
				   WHERE id='%d' ",$owner,$address,$mob1,$mob2,$id); 
		   if(!($resu=mysql_query($query_up))){echo $query_up.mysql_error(); exit;}
   if($_FILES["mimg"]["name"]!="") 
		{
				 
			 $fileload = $_FILES["mimg"]["name"];
			
			 $file_ext = explode(".",$fileload);
			 $myattach="mimg_".$id.".".$file_ext[1];
			 
			$destpath=$uploadpath.$myattach;
				 
			$file1 = move_uploaded_file($_FILES["mimg"]["tmp_name"],$destpath); 
			 $updatecategory=sprintf("UPDATE location SET mimg ='%s' WHERE id ='%d'", $myattach, $id);
			if(!($result = mysql_query($updatecategory))){echo $updatecategory.mysql_error();exit;}
		}	
		
		header("Location:add-contact.php?flag=dn");
		exit;
		
	
}
?>
