My scenario is like this:
<input type="file" name="image[]" />
<input type="file" name="image[]" />
<input type="file" name="image[]" />
<input type="file" name="image[]" />
My database field table is:
ID = 1
image1 = image1.jpg
image2 = image2.jpg
image3 = image3.jpg
image4 = image4.jpg
Let’s say the row id = 1 has already had values inserted previously and if the user wants to update image1 and image 4 so they will browse and select their desired image file and they leave the image2 and image3 blank.
Here’s the concept after executing mysql query:
ID = 1
image1 = newimage1.jpg
image2 = image2.jpg
image3 = image3.jpg
image4 = newimage4.jpg
How do I do the validating query?
Currently my code is like this and I have no idea how to continue from here as I’m still new to PHP/mysql.
foreach ($_FILES['product_image']['name'] as $key => $value) {
if(!empty($value)) {
`$upt=mysql_query("update products_list set` `image1='$pic1',image2='$pic2',image3='$pic3',image4='$pic4' where id='$id'");`
}
}
Hope this is clear to you guys. Thanks in advance. =)
You could use a counter to update the correct field:
Of course, this would mean that you would have to update the same record upto four times depending on what is sent from your form. Also, you should escape the user input using something like
mysql_escape_string().