PHP : MySQL-PDO to delete the record

MySql Database!

seard 

Find the record that has to be delete !

deletr

Now press the delete button!

recsucc

Record deleted After then look your Database.

afdelrs

PHP code (delete.php) for above..

<form action="delete.php" method="post">
<?php
$text="";$text1="";$text2=""; $btn="";
$hid="style='visibility:hidden'";
$r1="";$r2="";$r3="";$nt="";
$codeerr="";
$code="";
$flag=0;
if(isset($_POST["submit"]))
{
if(empty($_POST["t1"]))
{
$codeerr="Data Missing";
$flag=0;
}
else if(is_numeric(trim($_POST["t1"]))==false)
{
$codeerr="Accept Numeric value only";
$flag=0;
}
else
{
$code=$_POST["t1"];
$flag=1;
}
}
?>
<?php
if($flag!=0)
{
$server='localhost';
$username='root';
$password='';
$cnt=0;
try
{
$db=new PDO("mysql: host=$server; dbname=softaid",$username, $password);
$result=$db->query('select *from student where rollno='.$code);
$result->setFetchMode(PDO::FETCH_ASSOC);
$row=$result->fetch();
$cnt=count($row);
if($cnt>1)
{
$r1=$row["rollno"];     	
$r2=$row["sname"]; 
$r3=$row["scourse"];
$hid="style='visibility:visible'"; 
if(isset($_POST["submit"])) 
{ 
 $btn="<input type='submit' name='del' value='Delete' style='border-radius:5px; padding:2px; color:maroon' />";      
} 
}
else
{
echo"<h2 style=' text-align:center'>Record not Found</h2>";
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
if(isset($_POST['del']))
{
$rr=$_POST["ro"];
$server='localhost';
$username='root';
$password='';
$cnt=0;	
$db=new PDO("mysql: host=$server; dbname=softaid",$username, $password);
$stmt=$db->prepare("delete from student where rollno = :rollno");
$stmt->bindParam(':rollno',$rr);		
$count=$stmt->execute(); 
if($count>0)
{
echo "<h2 style=' text-align:center'>Record Deleted</h2>";
}
}
?>
<table  style="margin:auto; background-color:#FFF; color:#C03;   ">
<tr>
</tr>
<tr>
</tr>
</table>
<div style="width:695px; padding:13px 0px; border-radius:30px 30px 0 0;
 background-color:#00A7CA; color:#FFF; margin:auto; font-size:20px;font-family:Tahoma,
 Geneva, sans-serif; text-align:center;">Delete Record</div>
<table  style="width:695px; margin:auto; font-family:Tahoma, Geneva, sans-serif;
 color:#666; background-color:#FF9; text-align:center">
<tr>
<td >Enter Student Roll No.</td>
<td width="300px"><input type="text" name="t1" style="width:100%; height:25px"
 placeholder="<?php echo $codeerr ?>"  /></td>
<td >
<input type="submit" name="submit" value="search" style="padding:3px; width:100px; font-size:18px" />
 </td>
</tr>
</table>
<div style="width:695px; padding:20px 0px; border-radius:0px 0px 20px 20px;
 background-color:#00A7CA; color:#FFF; margin:auto; font-size:18px; text-align:center;"></div>
<br />
<div <?php echo $hid; ?>
<div style="width:500px; padding:13px 0px; border-radius:30px 30px 0 0; 
background-color:#00A7CA; color:#FFF; margin:auto; font-size:20px;font-family:Tahoma,
 Geneva, sans-serif; text-align:center;">Searching Result</div>
<table  border="1" style="width:500px; margin:auto; font-family:Tahoma, Geneva, sans-serif;
 color:#666; background-color:#FF9; text-align:center">
<tr>
<th>Roll NO.</th><th>Name</th><th>Course</th>
</tr>
<tr><td colspan="3"><?php echo $nt; ?></td></tr>
<tr>
<td><input type="text" name="ro" value="<?php echo $r1; ?>" /></td><td><?php echo $r2; ?></td>
<td><?php echo $r3; ?></td><td><?php echo $btn; ?></td>
</tr>
</table>
<div style="width:500px; padding:20px 0px; border-radius:0px 0px 20px 20px; 
background-color:#00A7CA; color:#FFF; margin:auto; font-size:18px; text-align:center;"></div>
</div>
</form>