In which part of the code should the condition !empty($test) and file_exists() be added to prevent database entry and email sending before file upload?
To prevent database entry and email sending before file upload, the condition !empty($test) and file_exists() should be added before the database insertion and email sending code. This ensures that the file has been successfully uploaded before proceeding with the database entry and email sending processes.
if (!empty($test) && file_exists($test)) {
// Proceed with database entry and email sending
// Database insertion code here
// Email sending code here
} else {
// Handle the case where the file does not exist or is empty
echo "File upload failed. Please try again.";
}