How to update (edit) MYSQL data in PHP?



Please Login or Register to process.

I'm trying to edit and upload the details to the MYSQL database using PHP programming 
The form having two dynamic dropdowns onClick event ajax function added an option getting from the database. 
While editing.


echo $description = $res['des'];

echo $frequency = $res['freq'];

echo $issuedate = $res['i_date'];

echo $validitydate = $res['v_date'];

echo $email = $res['e_mail'];

echo $datetosend = $res['d_to_send'];


Right here I'm getting

After that


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

  $id = $_POST['id'];

$description = mysqli_real_escape_string($conn,$_POST['description']);

  $frequency = mysqli_real_escape_string($conn,$_POST['frequency']);

  $issuedate = mysqli_real_escape_string($conn,$_POST['issuedate']);

  $validitydate =mysqli_real_escape_string($conn,$_POST['validitydate']);

  $email = mysqli_real_escape_string($conn,$_POST['email']);

  $datetosend =mysqli_real_escape_string($conn,$_POST['datetosend']);

$result=mysqli_query($conn,"Update added_date SET des='$description', freq='$frequency', i_date='$issuedate', v_date='$validitydate',e_mail='$email',d_to_send='datetosend' ,Where id=$id");

if ($result) {



  echo "sorry";




I am getting "Sorry". I want to update data using PHP with the MYSQL database but the else part is working well. I need that the update operation works well. I need help with data editing in PHP with MYSQL. 


asked 27 Aug 2020 in PHP by mishal(180 Points)


2 Answers
answered 27 Aug 2020 by vishalrana1(7.3K Points)

Are you getting id value?  Kindly GET id from 

$id = $_GET['id'];  

GET id from URL and create an input box as type hidden. The input box name will be id. This id will help you update a unique row using PHP. 

<input type="hidden" name="id" value=<?php echo $_GET['id'];?>>

You have an issue with your MYSQL query in PHP. Kindly remove the comma(,) from the last variable also you missed $ sign from the last variable in update query using PHP . 

Check the code lines below.

$result=mysqli_query($conn,"UPDATE added_date SET des='$description', freq='$frequency', i_date='$issuedate', v_date='$validitydate',e_mail='$email',d_to_send='$datetosend'  WHERE id=$id");

You have added extra comma at the last variable near about WHERE. We do not need to add the last comma.


answered 27 Aug 2020 by shakti(9.1K Points) (edited)

We use update operation in PHP to update the MYSQL database. This operation is known as edit operation or data modification operation in PHP. For data update operation, first of all, we fetch the data from the MYSQL database in HTML form. This is known as fetching already inserted data and display in the input box.  Let's understand update operation in steps - 

How to update or edit data in PHP? 

1. Create a database with a  table. 

2. Insert the data into the database. You can use a signup form to insert data in PHP. We will update it. 

3. Fetch data from the database and display the values in the form input box. 

4. We update or edit data after fetching data from the MYSQL database. 

5. Kindly GET id value from the URL. We use id to update or edit unique column. 

6. Update button and update query. 

You can check the tutorial of update operation - 

Update operation in PHP

If you want to learn the advanced CRUD app then reference it for you. 

CRUD Application in PHP


Related Questions :-

Your Answer

You can post your answer after login..