Update data from the database  using php: You need to identify the data you want to update to do this the following steps are taken.
Update data from the database  using php

Create a link

Update data from the database  using php .On the page where you have displayed the data create a link
<a href=”updatePage.php?varable=<?php echo($row['id']); ?>” >Update</a>

Explanation of Update data from the database  using php

We have created a link which points toward another php page where we will write our update code.
“?” this operator is to tell the link a variable is made which has the id stored in it. In this way, we can send the id of the data we want to update to the update page.

Getting value on the other page

To get value on the other page by using data form database using php $_GET function is used with isset function we have discussed about it earlier
If(isset($_GET[‘variable’])){
$variable=($_GET[‘variable’];
}

Using the html

Html is same as we used in the insert code

HTML CODE

<form method="post">
 <div class="row form-group">
 <div class="col-md-6">
 <label for="fname">First Name</label>
 <input type="text" id="fname" name="firstname" class="form-control" placeholder="Your firstname">
 </div>
 <div class="col-md-6">
 <label for="lname">Last Name</label>
 <input type="text" id="lname" name="lastname" class="form-control" placeholder="Your lastname">
 </div>
 </div>

 <div class="row form-group">
 <div class="col-md-12">
 <label for="email">Email</label>
 <input type="text" id="email" name="email" class="form-control" placeholder="Your email address">
 </div>
 </div>

 <div class="row form-group">
 <div class="col-md-12">
 <label for="subject">phone</label>
 <input type="number" id="subject" name="phone" class="form-control" placeholder="Your subject of this message">
 </div>
 </div>

 <div class="row form-group">
 <div class="col-md-12">
 <label for="message">Message</label>
 <textarea name="message" id="message" name="message" cols="30" rows="10" class="form-control" placeholder="Write us something"></textarea>
 </div>
 </div>
 <div class="form-group">
 <input type="submit" name="submit" value="Send Message" class="btn btn-primary">
 </div>
<div class="s-12" id="mes"><p id="para"><?php if(isset($error)){ echo("$error");} ?></p></div>
 </form>

Php code

if(isset($_GET[variable]))
{
  $ variable =$_GET[variable];
  if(isset($_POST['submit']))
  {
$firstname=$_POST['firstname'];
 $email=$_POST['email'];
 $lastname=$_POST['lastname'];
 $phone=$_POST['phone'];
 $mess=$_POST['message'];
$query=” UPDATE `food` SET ` first_name `='$firstname,` email `='$email,` secound-name `='$secound-name,` phone `='$phone ,` message `='$message WHERE  id='$variable

 $result=mysqli_query($connect,$query);
 if(!$result)
 {
 die("Query failder" . mysqli_error($connect));
 }
}
}
Just query is different at this point and all the other things are the same

Summary

 You need to send the id to the other page to identify the data you want to update and get the id on the other page and check if submit get data from the form and run the query.
Previous Lecture