<?php $picurl=$row['PicUrl']; >?
<td><input type="file" name="userfile" ></td>

Dani AI

Generated

Browsers will not let you prefill a file input for security reasons, so you cannot place a server-side filename into the file control itself (see MDN input file). was right to suggest showing the name in a label or an image preview instead. A reliable pattern is: show the existing filename (or thumbnail) as plain text, keep a hidden field with that DB value, let the user choose a new file, and on submit keep the existing file if no new upload arrived.

Example pattern (HTML + small client update):

<form method="post" enctype="multipart/form-data">
  <input type="text" id="shownName" value="<?php echo htmlspecialchars($existingFile); ?>" readonly>
  <input type="file" id="fileInput" name="uploadFile">
  <input type="hidden" name="existing_file" value="<?php echo htmlspecialchars($existingFile); ?>">
  <button type="submit">Save</button>
</form>

<script>
document.getElementById('fileInput').addEventListener('change', function () {
  var name = this.files && this.files.length ? this.files[0].name : document.getElementById('shownName').value;
  document.getElementById('shownName').value = name;
});
</script>

Server-side, check whether a file was actually uploaded and fall back to the hidden value if not. Use the PHP upload error constants to detect no-file uploads and validate/move the file when present:

<?php
$existing = $_POST['existing_file'] ?? '';
if (isset($_FILES['uploadFile']) && $_FILES['uploadFile']['error'] !== UPLOAD_ERR_NO_FILE) {
  // validate type/size, move_uploaded_file(...), set $finalName
} else {
  $finalName = $existing;
}
?>

Notes: ensure the form has enctype="multipart/form-data", never trust client filenames (sanitize or generate unique names), and watch upload_max_filesize/post_max_size. For full upload behavior and error codes see PHP file uploads.

I'm not sure the file input can accomodate that, you should use a label around the input and put the file name in there.

echo "<td><label>{$row["PicURL"]} <input type=\"file\" name=\"usefile\"> </label></td>";

Alternatively display the file as an img tag to show the user what has already been chosen?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.