<? session_start(); ?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d799}
.mnu{margin-left:5}
</style>

<?
include("opendb.php");
$brcode = $_SESSION['brcode'];
$submit=$_REQUEST['submit'];
$brname=$_REQUEST['brname'];
$braddr=$_REQUEST['braddr'];
$gst=$_REQUEST['gst'];
$state=$_REQUEST['state'];
if($submit)
{
    $code=substr($brname,0,3).substr(time(),7,3); 
    $code=str_replace(' ','-',$code);
    $res=mysqli_query($db,"select * from consign_mast where name='$brname' ");
    if(mysqli_num_rows($res)>0)
    {
        print "<script>submit='false';document.f1.brname.value='';alert('Duplicate Entry');location.reload();</script>";
        return;
    }
    else
    {
        $sql="insert into consign_mast values('".strtoupper($brname)."','$braddr','$brcode','$gst','$state')";
        mysqli_query($db,$sql) or die(mysqli_error($db));;        print "Data has been Saved";
    }
}
?>

<script>
function validate()
{
    submit="true";
    if(document.f1.divis.selectedIndex<=0)
    {submit="false"; alert('Invalid Division');}

    if(document.f1.brname.value.length<3)
    {submit="false"; alert('Invalid branch name');}

    if(submit=="false")
    return false;
}
</script>

<body bgcolor=fcfff1>
<font color=green>
<h3>Branch Creation</h3></font>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return validate()">
<table border=0  cellspacing=2 cellpadding=5>

<tr><td>Consignee Name</td><td><input type=text name='brname' size=40></td></tr>

<tr><td>Address</td><td><input type=text name='braddr' size=60></td></tr>
<tr><td>GST NO</td><td><input type=text name='gst' size=30></td></tr>
<tr><td>State</td><td><input type=text name='state' size=30></td></tr>

<tr><td colspan=2 align=center><input type=submit name='submit' value='  S A V E  '> <input type=button value='   C A N C E L    ' onClick=document.location='main.htm'></td></tr>
</table>
</form>
<?

$result=mysqli_query($db,"select * from consign_mast order by name asc ")or die(mysqli_error($db));
?>
<table border=0  cellspacing=2 cellpadding=5>
<th>No. <th>Consignee Name <th>Address <th>GSTNO</th>
<?
$i=1;
while($row=mysqli_fetch_array($result))
{
 print "\n<tr bgcolor='c1d7bf' onMouseOver=bgColor='Pink'; onMouseOut=bgColor='c1d7bf'; ><td>".$i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[3]</td>";
}
?>
</table>


