<?php
session_start(); 
include ("dbinfo.php");   
$error=''; 

//--------------------------------------- add sample ----------------------------------
if (isset($_POST['btn_samsubmit'])) 
{
	$cusid=$_POST['txt_cusid'];
	$comname=$_POST['txt_comname'];
	$comaddress=$_POST['txt_comaddress'];
	$cusname=$_POST['txt_cusname'];
	$cuscontact=$_POST['txt_cuscontact'];
	$cusemail=$_POST['txt_cusemail'];

	$sswatch=$_POST['txt_sswatch'];
	$sdate=$_POST['txt_sdate'];
	$sstatus=$_POST['txt_sstatus'];
	$snotes=$_POST['txt_snotes'];
	$record_date=date('y-m-d H:i:s');
	
	if($cusid=='')
	{
		$query=mysqli_query($conn,"SELECT * FROM `customer` ORDER BY `cus_id` desc limit 1")or die(mysqli_error($conn));
		$row = mysqli_fetch_array($query);
		$cus_id=$row['cus_id']+1; 
		
		$cus_query=mysqli_query($conn,"INSERT INTO `customer`(`com_name`, `com_addr`, `cus_name`, `cus_contact`, `cus_email`) VALUES('$comname','$comaddress','$cusname','$cuscontact','$cusemail')")or die(mysqli_error($conn));
	} 
	else {
		$cus_id=$cusid;
	}
	
	$sam_query=mysqli_query($conn,"INSERT INTO `track_sample`(`cus_id`, `sw_id`, `date`, `status`, `note`, `record_date`) VALUES('$cus_id','$sswatch','$sdate','$sstatus','$snotes','$record_date')")or die(mysqli_error($conn));
	
	if($sam_query==true)
	{
	header('location:sample.php?status=1');
	}
	else
	{
	header('location:sample.php?status=3');
	}

}

?>