Welcome to Techno Smarter QA, Question, Answer forum. Ask questions, receive answers, or help someone. Join Now
+1 vote
47 views

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


while($res=mysqli_fetch_array($result)){

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

 

<?php

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) {

header("location:update_front.php");

}else{

  echo "sorry";

}

}

 ?>

 

I am getting "Sorry" . I want to update data using PHP with 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 . 

in PHP by (160 points) 4

2 Answers

+1 vote

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.

by (7.1k points) 9 27 62
+1 vote

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 the 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 tutorial of update operation - 

Update operation in PHP

If you want learn advanced CRUD app then reference for you. 

CRUD Application in PHP

by (8.9k points) 10 24 62
edited by
...