I am learning CRUD in php mysqli insert and delete is working but when I tried to update any record, the new value record gets inserted to new row instead of replacing old record value to new value. i have following code for having code for update, please suggest what is missing
home page
<?php
include 'db.php';
if(isset($_GET['del_id']))
{
$del="DELETE FROM student WHERE id = '$_GET[del_id]'";
$run=mysqli_query($con,$del);
}
?>
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
</head>
<body>
<div class="container">
<table class="table">
<th>Id</th>
<th>Name</th>
<th>Password</th>
<th>Address</th>
<th>View</th>
<th>Update</th>
<th>Delete</th>
<?php
include 'db.php';
$show="select * from student";
$run=mysqli_query($con,$show);
while($row=mysqli_fetch_array($run))
{
echo '
<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[2].'</td>
<td>'.$row[3].'</td>
<td><a class="btn btn-success btn-xs" href="view.php?user_id='.$row[0].'">View</a></td>
<td><a class="btn btn-info btn-xs" href="home.php?update_id='.$row[0].'">Update</a></td>
<td><a class="btn btn-danger btn-xs "href="test.php?del_id='.$row[0].'">Delete</a></td>
</tr>
';
}
?>
</table>
</body>
</html>`
update page
<?php
include 'db.php';
if(isset($_GET['update_id']))
{
$up="SELECT FROM student WHERE id = '$_GET[update_id]'";
$run=mysqli_query($con,$up);
while($row=mysqli_fetch_array($run))
{
$name=$row['txtname'];
$pass=$row['txtpass'];
$add=$row['txtadd'];
}
}
else
{
$name='';
$pass='';
$add='';
}
?>
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
</head>
<body>
<div class="container">
<form class="form-horizontal" role="form" action="process.php" method="POST">
<div class="form-group">
<label class="control-label col-sm-2" for="name">name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="txtname" value="<?php echo $name;?>" placeholder="Enter Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" name="txtpass" value="<?php echo $pass;?>" placeholder="Enter password">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Address:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="address" name="txtadd" value="<?php echo $add;?>" placeholder="Enter Address ">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" name="submit_form">Submit</button>
</div>
</div>
</form>
</div>
</body>
</html>