<?php 

include("config.php");

$dresult=mysql_query("select * from customer WHERE nid='$_POST[nid]' ");
$drow=mysql_fetch_array($dresult);

if($drow == ""){
	
$dresult=mysql_query("select * from customer WHERE personal_phn='$_POST[personal_phn]' ");
$drow=mysql_fetch_array($dresult);	
if($drow == ""){	
mysql_query("ANALYZE TABLE customer");
	
$kresult = mysql_query("SHOW TABLE STATUS LIKE 'customer'");
$krow = mysql_fetch_array($kresult);
$id=$krow['Auto_increment'];

$uploadFolder = "uploads/";	
if (!file_exists($uploadFolder)) {
    mkdir($uploadFolder, 0777, true);
}
	
	
$filename = $_FILES['file1']['name'];
if($filename!=""){

$ext = substr($filename, strrpos($filename, '.') + 1); 
$a=$id."_1.".$ext;

copy ($_FILES['file1']['tmp_name'], "uploads/".$a);
}else{$a="";}
	
$filename = $_FILES['file2']['name'];
if($filename!=""){

$ext = substr($filename, strrpos($filename, '.') + 1); 
$b=$id."_2.".$ext;

copy ($_FILES['file2']['tmp_name'], "uploads/".$b);
}else{$b="";}

	
	mysql_query("INSERT INTO customer (customer_name, contact_person, personal_phn, nid, personal_email, address,file1,file2) VALUES ( 
'$_POST[customer_name]','$_POST[contact_person]','$_POST[personal_phn]','$_POST[nid]','$_POST[personal_email]','$_POST[address]','$a','$b')");
header("location:add_client.php");
}else{
header("location:add_client.php?info=Phone No $_POST[personal_phn] is exist on this account $drow[id]");
	}

}else{
header("location:add_client.php?info=Nid  $_POST[nid] is exist on this account $drow[id]");
	}
?>