How to keep the previous uploaded image (in db) after submitting a form without selecting a new image to be uploaded
What about something like this?
if(!empty($_FILES['fileToUpload']['name'])) //new image uploaded
{
//process your image and data
$sql = "UPDATE table SET name=$someName, image=$someImageName,... WHERE id = $someId";//save to DB with new image name
}
else // no image uploaded
{
// save data, but no change the image column in MYSQL, so it will stay the same value
$sql = "UPDATE table SET name=$someName,... WHERE id = $someId";//save to DB but no change image column
}
//process SQL query in $sql
Make a if clause that checks if fileupload input is empty or not. If it is empty do not execute query.
Use input type="file" without attribute value.
<input type="file" name="fileToUpload" id="fileToUpload" />
Here is example for if clause
if(!empty($_FILES['fileToUpload']['name'])) {
$origFile = $_FILES['fileToUpload']['name'];
$tempFile = $_FILES['fileToUpload']['tmp_name'];
$sizeFile = $_FILES['fileToUpload']['size'];
/* UPLOAD CODE GOES HERE */
}