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

$str=" ";



$lname= mysqli_real_escape_string($con,trim($_POST['lname']));
$loctype= mysqli_real_escape_string($con,trim($_POST['loctype']));


$edate=date("Y-m-d");
$userid=$_SESSION['rm_id'];

if (empty($lname)) {
    $lname = '';
    echo "<script type='text/javascript'>alert('Please Enter Location Name!');</script>";
	echo "<script>document.location='admin_location_view.php'</script>"; 
}

else {
$query=mysqli_query($con," select * from stock_locations where loc_name='$lname'  ")or die(mysqli_error($con));
    $count=mysqli_num_rows($query);
if ($count>0)
{
	echo "<script type='text/javascript'>alert('Exsisting Location!');</script>";
	echo "<script>document.location='admin_location_view.php'</script>"; 
}

else {

		if ( mysqli_query($con,"INSERT INTO stock_locations(loc_name,loc_type,loc_active) 
			                                 VALUES('$lname','$loctype',1)  ")or die(mysqli_error($con)))
	        {
					
				echo "<script>document.location='admin_location_view.php'</script>"; 
	     	 
			}
}	


} 

?>