Forum Moderators: coopster
$pic = $_POST['Pic'];
if ($updatestockdetails) {echo "<p>Selected photos deleted successfully.</p>"; }
if (!empty($row['pic1'])) { echo '<div class="editpics"><img src="images/carpictures/' . $pic1 . '" width="100"><br /><label for="Pic[]">Delete Photo 1</label><input name="Pic[]" type="checkbox" class="formfield" value="'.$pic1.'" /></div>'; }
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors','1');
$htm = ''; // Assign to variable and echo once at the end instead of echo, echo, echo
$maxPics = 5; // Maybe you need this in other places?
for ($i = 1; $i <= $maxPics; $i++) {
if (!empty($row['pic'.$i])) {
// For larger blocks of text/HTML it can be easier to use HEREDOC syntax
$htm .= <<<EOD
<div class="editpics"><img src="images/carpictures/{$row['pic'.$i]}" width="100"><br>
<label for="pic$i">Delete Photo $i</label><input name="Pic[]" id="pic$i" type="checkbox" class="formfield" value="$i"></div>
EOD;
}
}
echo $htm;
// Note that $_POST['Pic'] might not be set at all if no checkboxes are checked!
$pics = isset($_POST['Pic']) ? $_POST['Pic'] : array();
// The array "key" is meaningless here, the pic# is stored in the value
foreach ($pics as $value) {
// (NB: Check for errors, probably wise to break on first error)
$mysqli->query("UPDATE cars SET Pic$value = NULL where carid = $carid");
}