<?
session_start();
include("opendb.php");
if($sv)
{
 if(strlen($config)<=1)
   return;
 $sql="insert into configmaster(model,config) values('$model','$config')";
 mysqli_query($db,$sql) or die('error:'.mysqli_error());
}
if($del)
{
  $sql="delete from configmaster where code='$code'";
 mysqli_query($db,$sql) or die(mysqli_error());
}
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<script>
function valid()
{
 if(document.f1.config.value.length<=0)
 { alert ('Invalid Configuration'); return false;}
}
</script>
<center>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()"> 
<table cellspacing=1 cellpadding=5 bgcolor=steelblue>
<tr><td align=center colspan=2><font color=white><b>CONFIGURATION MASTER</td> </tr>
<tr bgcolor=white><td>Model </td><td>
<select name='model'>
<?
$re=mysqli_query($db,"select * from machmaster order by maname");
while($row=mysqli_fetch_array($re))
{
 print "<option>$row[1]</option>";
}
?>
</select>
</td></tr>
<tr bgcolor=white><td>Configuration </td><td><input type=text size=50 name='config'></td></tr>
<tr><td colspan=2 align=center><input type=submit value='Save' name='sv'></td></tr>
</table>
</form>

<?
$result=mysqli_query($db,"select * from configmaster order by model");
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 "\n<tr bgcolor=white><form action='$PHP_SELF'><input type=hidden name='code' value='$row[0]'><td>".$i++."</td><td>$row[1]</td><td>$row[2]</td><td><input type=submit value='Del' name='del'></td></form></tr>";
}
?>
</table>
