0

I have this edit form page having two fields and a link to view previous uploaded file and also the user can upload a new file to replace the new one. If user hits on view file it works, but if he edits other fields and do not upload file, after he hits on save, the first file is erased, just because no file is uploaded, but if he uploads a new file, it works. What can i do to keep the previous file even if the user does not upload new one but only edit the others fields ? Any help please!

1- the form

 $id_rd = intval($_GET["id_rd"]); 
 $qryz="SELECT * FROM claims_follow_up.Reconciliation_Details where  id_rd ='$id_rd' ";
 $res = mysqli_query($dbc, $qryz);
 $dd=mysqli_fetch_array($res);

 <form action="update.php" method="post"  enctype="multipart/form-data"> 
 <input type="hidden" name= "id_rd"  value="<?=$dd['id_rd']?> " >
 <label>Patient Amount</label> 
 <input type="text" name= "Patient_Amount" value="   <?=$dd['Patient_Amount']?>">
<label>Page_#</label> 
<input type="text" name="Page" value="<?=$dd['Page']?> " />
<label>Upload new file</label> 
 <input type="file" name="file"/>
<a href="uploads/<?php echo $dd['PDF_Report1'] ?>" target="_blank">view file</a> 
 <input value="Edit" type="submit" >
</form>

update.php

extract($_POST) ; 
$file1=$_FILES["file"]["name"]; 

list($name, $ext) = explode(".", $file1);  

 $ext=".".$ext; 

$chemin = "./uploads/".$file1;
move_uploaded_file($_FILES["file"]["tmp_name"],$chemin); 
$sql = "update claims_follow_up.Reconciliation_Details set Patient_Amount='$Patient_Amount', Page='$Page',File='$file1'
 where id_rd='$id_rd'";
$res = mysqli_query($dbc, $sql)
baptpro
  • 23
  • 5

0 Answers0