I am trying to delete pictures from the server that are associated with a specific item, that way when the user clicks on the delete button it will delete the item as well as all pictures associated with it, after doing a bunch of searching and experimenting I have this code, I comented out all the code that deletes things in favor of just echoing each picture because I thought if I can get it to echo all the picture names then I would be able to uncomment the delete staments and allow it to delete, rather then having to constantly replace information on the server to test.
<?php
session_start();
include 'conection.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_SESSION['user_id']))
{
$stock = $_POST['refStk'];
$refId = $_POST['refID'];
$numPics = 0;
$pics = 0;
$result = mysql_query("SELECT * FROM inventory WHERE id = '$refId'") or die(mysql_error());
$row = mysql_fetch_array($result);
$picRes = mysql_query("SELECT * FROM uploads WHERE ref_id = '$stock'");
if(isset($_POST['confirm']))
{
$stock = $_POST['refStk'];
$id = $_POST['refID'];
/*$query="DELETE FROM inventory WHERE id='".$id."'";
$query_2="DELETE FROM uploads WHERE ref_id ='".$stock."'";
if (!mysql_query($query,$con) || !mysql_query($query_2,$con))
{
die('Error: ' . mysql_error());
}
if(mysql_query($query,$con) && mysql_query($query_2,$con))
{
echo 'Vehicle Removed';
}*/
while($pics <= $numPics)
{
$delFile = 'pics/' . $_POST['picName'];
echo $delFile;
$pics++;
/*if (file_exists($delFile))
{
//unlink($delFile);
echo $delFile;
}else
{
echo 'file does not exist';
}*/
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>File Delete</title>
</head>
<body onUnload="window.addEventListener("unload", invalidateBackCache, true)"><center>
<table border = '1'>
<tr>
<th>Stock Number</th><th>Year</th><th>Make</th><th>Model</th><th>Mileage</th><th>Transmition</th><th>Body Style</th><th>Location</th><th>Asking Price</th>
</tr>
<tr>
<td><?php echo $row['stock']?></td><td><?php echo $row['year']?></td><td><?php echo $row['make']?></td><td><?php echo $row['model']?></td><td><?php echo $row['mileage']?></td><td><?php echo $row['transmition']?></td><td><?php echo $row['body_style']?></td><td><?php echo $row['location']?></td><td><?php echo $row['ask_price']?></td>
</tr>
</table><br /><br />
<form name="delete" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<?php
while($picRow = mysql_fetch_array($picRes))
{
$numPics++
?>
<img src="<?php echo "pics/".$picRow['name']; ?>" width="110" height="83" />
<input type="hidden" name="picName" value="<?php echo $picRow['name']; ?>" />
<?php
}
?>
<h1>Are you sure you want to delete all files associated with this vehicle?</h1>
<input type="hidden" name="refID" value="<?php echo $refId ?>" />
<input type="hidden" name="refStk" value="<?php echo $stock ?>" />
<input type="submit" name="confirm" value="Yes" />
<a href = vehicleSelect.php><input type="button" value="No" /></a>
</form>
</center>
</body>
</html>
<?php
}else
{
echo "<br /><br /><br /><br />";
echo "<strong><center>"."You Are Not Authorized To view This Page......<a href='admin.php'>Please Login First !!</a>"."</center></strong>";
}
?>
all I get with this is the last picture posted, I have tried having each picture have its own form but then I errors trying to get the names to displayat all as if i am not even getting the information transmitted