I have a photo gallery and want to update multiple captions at once via form input. I've tried to research this but I think I'm in way over my head. This is what I have so far but it's not working..
The data is saved in an SQL table called "gallery". An example row might look like:
gallery_id(key) = some number
product_id = 500
photo = photo.jpg
caption = 'look at this picture'
My form inputs are generated like this:
$sql = mysql_query("SELECT * FROM gallery WHERE product_id = 500");
while($row = mysql_fetch_array($sql)) { $photo=$row['photo']; $caption=$row['caption']; echo '<img src="$photo"/>'; echo '<input name="cap['.$caption.']" id="cap['.$caption.']" value="'.$caption.'" />'; }
So once I submit the form I start to access my inputs like this but I hit a wall..
if( isset($_POST['cap']) && is_array($_POST['cap']) ) {
foreach($_POST['cap'] as $cap) {
mysql_query("UPDATE gallery
SET caption=$caption
WHERE ???????");
}
}
I don't know how to tell the database where to put these inputs and as far as I can tell you can't pass more than one variable in a foreach loop.