This is my code for uploading multiple images in columns with names img0,img1,img2,img3 etc. How to update table by iterating through column names? Do i need to concatenate?
if(isset($_POST['submit'])){
$uploadsDir = "images/property/";
$allowedFileType = array('jpg','png','jpeg');
$error="";
// Velidate if files exist
if (!empty(array_filter($_FILES['fileUpload']['name']))) {
$total= count($_FILES['fileUpload']['name']);
if($total > 6){
$error="please select less than 6 pictures";
}
// Loop through file items
for($i=0; $i<$total; $i++){
// Get files upload path
$fileName = $_FILES['fileUpload']['name'][$i];
$tempLocation = $_FILES['fileUpload']['tmp_name'][$i];
$targetFilePath = $uploadsDir . $fileName;
$fileType = strtolower(pathinfo($targetFilePath, PATHINFO_EXTENSION));
$uploadOk = 1;
if(in_array($fileType, $allowedFileType)){
if(move_uploaded_file($tempLocation, $targetFilePath)){
$sqlVal = "('".$fileName."')";
} else {
$error="uploading error";
}
} else {
$error="please select valid image";
}
// Add into MySQL database
if(!empty($sqlVal)) {
//the problem is here????????
$insert = $conn->query("UPDATE property (img???) VALUES $sqlVal");
if($insert) {
$error="success";
} else {
$error="database error";
}
}
}
} else {
$error="please select pictures to upload";
}
}
my table has column with names img0,img1,img2,img3,img4.I want to update each image in particular column can i do it with loop