MySqli_2 Edit Update Records

New PHP MySQL Tutorials in Urdu/Hindi part 32 editing-updating records in database

<?php 

mysql_connect("localhost","root","");
mysql_select_db("school");
$edit_record = $_GET['edit'];

$query = "select * from students where id='$edit_record'";

$run = mysql_query($query);

while ($row=mysql_fetch_array($run)){

$edit_form = $row['id']; $s_name = $row['student_name'];
$school_name = $row['school_name'];
$roll_no = $row['roll_no '];
$result = $row['result'];



}

?> <html>
<head><title>Student's Data</title></head>
<body>
<form action="edit.php?edit_form=<?php echo $edit_id;?>" method="post">
<table width="500" border="5" align="center">
<tr>
<td align="center" colspan="5" bgcolor="yellow"><h1>Updating Records</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" value="<?php echo $school_name; ?>"></td>
</tr>
<tr>
<td align="right">Roll No:</td>
<td><input type="text" name="roll" value="<?php echo $roll; ?>"></td>

</tr>
<tr>
<td align="right">Result:</td>
<td><input type="text" name="result" value="<?php echo $result; ?>"></td>
</tr>


<td align="center" colspan="5"><input type="submit" name="update" value="Update Now"></td>

</tr>

</table>
</form>

<h1 align="center"><?php echo @$_GET['deleted'];?></h1>
<h1 align="center"><?php echo @$_GET['Updated'];?></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</a></td>
<td><a href="Edit.php?edit=<?php echo $id;?>">Edit</a></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>";
}
}

?>




<?php 

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

$edit_id1 = $_GET['edit_form'];

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

$query1 = "update students set student_name='$name', school_name='$school', roll_no='$roll', result='$result' where id= '$edit_id1' ";

if (mysql_query($query1)){

header("location: students.php?updated=Data has been updated..")

}

}



?>




Edit.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>";

}

?>