MySqli_1 Delete

New PHP MySQL Tutorials in Urdu/Hindi part 30 deleting data from database


<html>
<head><title>Student's Data</title></head>
<body>
<form action="students.php" method="post">
<table width="500" border="5" align="center">
<tr>
<td align="center" colspan="5" bgcolor="yellow"><h1>Student's Registeration</h1></td>
</tr>
<tr>
<td align="right" >Student Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td align="right">School Name:</td>
<td><input type="text" name="school"></td>
</tr>
<tr>
<td align="right">Result:</td>
<td><input type="text" name="result"></td>
</tr>
<tr>
<td align="center" colspan="5"><input type="submit" name="submit" value="Submit Now"></td>
</tr></table>
</form>

<h1 align="center"><?php echo @$_GET['deleted'];?></h1><table width="800" border="5" align="center">
<tr>
<th>Serial No:</th>
<th>Student Name:</th>
<th>School No:</th>
<th>Roll No:</th>
<th>Status</th>
<th>Delete</th>
<th>Edit</th>
</tr>

<?php
mysql_connect("localhost","root","");
mysql_select_db("localhost");
$query1 = "select * from students";
$run = mysql_query($query1);
while($row=mysql_fetch_array($run))
{
$id= $row['id'];
$s_name = $row['student_name'];
$school_name = $row['school_name'];
$roll_no = $row['roll_no'];
$s_result= $row['result'];



?>
<tr align="center">
<td><?php echo $id;?></td>
<td><?php echo $s_name;?></td>
<td><?php echo $school_name;?></td>
<td><?php echo $roll_no;?></td>
<td><?php echo $s_result;?></td>
<td><a href="delete.php?del=<?php echo $id;?>">Delete</td>
<td>Edit<a href="Edit.php?edit=<?php echo $id;?>"></td>
</tr>
<?php } ?>
</table>
</body>

</html>

<?php  
mysql_connect("localhost","root","");
mysql_select_db("localhost");

if (isset($_POST['submit'])){

$name=$_POST['name'];
 $school=$_POST['school'];
 $roll=$_POST['roll'];
 $result=$_POST['result'];

$query= "insert into students(student_name,school_name,roll_no,result) values ('$name','$school','$roll','$result')";

if (mysql_query($query))
{
echo "<h1>Data Inserted</h1>";
}
}

?>


Delete.php
<?php 
mysql_connect("localhost","root","");
mysql_select_db("school");

$delete_id= $_GET['del'];
$query = "delete from students where id= '$delete_id'";

if (mysql_query($query)){

echo "<script>window.open('students.php?deleted=data has been deleted...','_self')</script>";

}
?>