<?
session_start();
include("../opendb.php");
include("../test.php");
if($code&&$act=='del')
{
 $q="delete from premodel where code='$code'";
 mysqli_query($db,$q);
}
if($save)
{
mysqli_query($db,"create table  premodel (code int(12) not null auto_increment,model varchar(200), primary key(code))");
 $re1=mysqli_query($db,"select * from  premodel where model='$model'")or die(mysqli_error($db));
 if(mysqli_num_rows($re1)>0)
  {
   print "<font color=red>Duplicate Entry</font>";
  }
 else{
 mysqli_query($db,"insert into   premodel (model) values('$model')");
 }
}
?>
<head>
<script>
 function valid()
 {
   if(document.f1.loc.value.length<=0)
   {
    alert("Insuffient entry");
    return false;
   }
}
function del(x)
{
 if(confirm('Do you want to delete this item ?'))
  document.location='<?print $PHP_SELF?>?code='+x+'&act=del';
}
</script>

<style>
tr{font-family:arial;font-size:13;background-color:white}
TH{COLOR:WHITE;BACKGROUND-COLOR:STEELBLUE}
</style>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<center>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit='return valid()'>
<table border=1>
<th COLSPAN=3>Add Model</TH>
<tr><td>Model</td><td><input type=text name='model' size=40></td>
  <td><input type=submit value='Add' name='save'></td></tr>
</table>
</form>
<?
 $re=mysqli_query($db,"select * from premodel order by model")or die(mysqli_error($db));
 $i=1;  
 print "<table cellspacing=1 cellpadding=3 bgcolor='gray'>";
 print "<th width=20>No <th>Source<th>Del";
while($row=mysqli_fetch_array($re))
{
 print "<tr><td>".$i++."</td><td>$row[1]</td><td align=center>";
?>
<input type=button value='Del' onClick=del('<?print $row[0]?>')></td></tr>
<?
}
?>
</table>

