Editing/Updating Image In CRUD App

Good day

I have written a CRUD code in prepared statement, the challenge i have is in the update query data, whenever
i tried updating/editing the data the images does not update to newly updated image in the table

HTML Form code

<form action="participantsController.php" method="POST" enctype="multipart/form-data">

  <?php

    $partID = $_GET['partEdit'];
    $ret = mysqli_query($connection, "select * from participants where partID = '$partID'");
    $cnt = 1;
    while ($row = mysqli_fetch_array($ret)) {

    ?>

<div class="form-group">
      <label >Upload business logo here <span class="text-danger mb-3">* </span> </label>
        <div>
          <input type="hidden" name="oldBizLogo" value="<?php echo $row['bizLogo']; ?>">
          <input type="file" name="imageBizLogo" id="imageBizLogo" class="form-control" >
          <img  src="../uploads/participants/<?=$bizLogo;?>" width="120" alt="Business Logo" class="img-thumbnail">
        </div>
    </div>

    <div class="form-group">
      <label >Upload participant profile image here <span class="text-danger mb-3">* </span> </label>
        <div>
          <input type="hidden" name="oldProfileImg"  value="<?php echo $row['profileImg']; ?>">
          <input type="file" name="imageProfileImg" id="imageProfileImg" class="form-control" >
          <img  src="../uploads/participants/<?=$profileImg;?>" width="120" alt="Profile Image"  class="img-thumbnail">
        </div>
    </div>
	
<?php }?>

</form>

Php code for updating

//Update page code
if(isset($_POST['partUpdate']))
{

  $partID = $_POST['partID'];

  $oldBizLogo = $_POST['oldBizLogo'];
  $oldProfileImg = $_POST['oldProfileImg'];
  
  if(isset($_FILES['imageBizLogo']['name'])&&($_FILES['imageBizLogo']['name']!="") || ($_FILES['imageProfileImg']['name'])&&($_FILES['imageProfileImg']['name']!=""))
  {
    $newBizLogo ="../uploads/participants/".$_FILES['imageBizLogo']['name'];
    $newProfileImg ="../uploads/participants/".$_FILES['imageProfileImg']['name'];

    unlink($oldBizLogo);
    unlink($oldProfileImg);

    move_uploaded_file($_FILES['imageBizLogo']['tmp_name'], $newBizLogo);
    move_uploaded_file($_FILES['imageProfileImg']['tmp_name'], $newProfileImg);
  }
  else{
    $newBizLogo = $oldBizLogo;
    $newProfileImg = $oldProfileImg;
  }
  $query = "UPDATE participants SET bizLogo=?,profileImg=?  WHERE partID=?";

  $stmt=$connection->prepare($query);
  $stmt->bind_param("ssi",$newBizLogo,$newProfileImg,$partID);

  $stmt->execute();

  $_SESSION['updateResponse']="Updated Successfully!";
  $_SESSION['updateRes_type']="primary";
  header('location:participantsAdd.php');

}
```Kindlyy help

Where do you get the partID field from in your update code? I don’t see that in the form anywhere. Having said that, I don’t see your partUpdate button either, perhaps there are other parts of the form that you haven’t shown.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.