<? 
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
 $code=substr($na,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);

if($save)
{
 mysqli_query($db,"insert into drv_master values('$code','$na','$br','$cnt','$brcode')") or die(mysqli_error());
 print "<font color=green>Data has been saved</font>";
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<body bgcolor='ivory'>
<center>
<h3> DRIVER MASTER</H3>
<form action='<?print $PHP_SELF?>'>
<table border=1>
<tr><td>Name </td><td><input type=text name='na' size=40></td></tr>
<tr><td>Branch</td><td><select name='br'>
<?
$re=mysqli_query($db,"select * from br_master where brcode='$brcode'")or die(mysqli_error());
while($row=mysqli_fetch_row($re))
{
 print "\n<option value='$row[0]'>$row[1]</option>";
}
?>
</select></td></tr>
<tr><td>Contact</td><td><input type=text name='cnt' size=40></td></tr>
<tr><td colspan=2 align=center><input type=submit value='SAVE' name='save'></td></tr>
</table>
</form>

<br>
<table cellspacing=1 cellpadding=3 width=50%>
<th>No <th>Name <th>Contact <th>Edit
<?
$i=1;
$result=mysqli_query($db,"select * from drv_master where brcode='$brcode' order by name")or die(mysqli_error());
while($row=mysqli_fetch_array($result))
{
 print "\n<form action='editdriver.php'><input type=hidden name='code' value='$row[0]'>";
 print "\n<tr><td align=center>".$i++."</td><td>$row[1]</td><td>$row[3]</td><td align=center><input type=submit value='Edit' name='edit'></form>\n</tr>";
}
?>
</table>
