<?
session_start();
include("opendb.php");
if($sv)
{
 if(strlen($maname)<=1)
   return;
 $code=substr($maname,0,3).date(dmys);
 $sql="insert into machmaster values('$code','$maname','$mtype')";
 mysqli_query($db,$sql) or die(mysqli_error());
 $maname="";
}
if($del)
{
  mysqli_query($db,"delete from machmaster where code='$code'");
}
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<script>
function valid()
{
 if(document.f1.maname.value.length<=0)
 { alert ('Invalid Machine Name'); return false;}
}
</script>
<center>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()"> 
<table cellspacing=1 cellpadding=5 bgcolor=lightsteelblue>
<tr><td align=center colspan=2><font color=white><b>MODEL MASTER</td> </tr>
<tr><td align=center bgcolor=white>
<table cellspacing=1 cellpadding=5>
<tr><td>Model Name </td><td><input type=text name='maname' size=40></td></tr>
<tr><td>Machine Type </td><td><select name='mtype'>
 <option>Wheeled Equipment</option>
 <option>Hydraulic Escavator</option>
 </select> <input type=submit value='Save' name='sv'>
</td></tr>
</table>
</td></tr>
</table>
</form>
<?
$result=mysqli_query($db,"select * from machmaster order by maname");
print "<table cellspacing=1 cellpadding=5 bgcolor='lightsteelblue'>";
print "<th>No <th>Name <th>Type <th>Del";
$i=1;
while($row=mysqli_fetch_row($result))
{
 print "<tr bgcolor=white><td>".$i++."</td><td>$row[1]</td><td>$row[2]</td>";
 print "<td><input type=button value='Del' onClick=del('$row[0]');></td></tr>";
}
?>
</table>
<script>
 function del(x)
 {
  if(confirm('Do you want to delete item?'))
  {
   document.location='<?print $PHP_SELF?>?code='+x+'&del=del';
  }
 }
</script>

