one thing you might look into changing is using mysql_fetch_assoc instead of mysql_fetch_array - i think it will make more of an array like what you’re looking for.
you might also echo out the value of a_row[image] each time in the while just to be sure it’s set…
Anyway I am going to post the guts of the page so maybe you can see what I am exactly doing. Also I am getting this error after I try and delete the image:
Error fetching category details: You have an error in your SQL syntax near ‘’ at line 1
Which I beleive has something to do with the $id variable not being populated after the deletion.
<?
//################# Delete Image from Folder
if ($action == "deleteimage")
{
$result = mysql_query("SELECT * FROM categories",$link);
while ($a_row = mysql_fetch_assoc ($result) )
{
unlink("/home/skgaston/public_html/CMS/full/pics/$a_row[image]");
}
$query = "DELETE FROM categories where image = '$a_row[image]'";
if (!mysql_query ($query, $link) )
{
die (mysql_error());
}
print "<table width=600 align=center bgcolor=ffffff><tr><td>Your image has been removed...</td></tr></table>";
}
//################# UPLOAD IMAGE TO FOLDER #################
if ($action == "upload")
{
//All the upload stuff
}
//############# If submit
if ($submit): // The category's details have
// been updated.
$sql = "UPDATE categories SET
Name='$name'
image='$userfile'
WHERE ID=$id";
if (@mysql_query($sql)) {
echo("<p>Category details updated.</p>");
} else {
echo("<p>Error updating category details: " .
mysql_error() . "</p>");
}
?>
<p><a href="cats.php">Return to Category list</a></p>
<?php
else: // Allow the user to edit the category
// with ID=$id
{
$cat=@mysql_query("SELECT * FROM categories WHERE ID=$id");
if (!$cat) {
echo("<p>Error fetching category details: " .
mysql_error() . "</p>");
// exit();
}
$cat = mysql_fetch_array($cat);
$name = $cat["name"];
$image = $cat["image"];
// Convert special characters for safe use
// as an HTML attribute.
$name = htmlspecialchars($name);
?>
<form action="<?=$PHP_SELF?>" method="post">
<p>Edit the category:<br />
Name: <input type="text" name="name" value="<?=$name?>" size="20" maxlength="255" /><br />
<input type="hidden" name="id" value="<?=$id?>" />
<input type="submit" name="submit" value="SUBMIT" /></p>
</form>
<?
if ($image == "")
//###################################
{
print "<CENTER><B>Manage Images</b></center><P>";
print"<FORM METHOD=\\"post\\" ACTION=\\"editcat.php\\" ENCTYPE=\\"multipart/form-data\\">";
print"<INPUT TYPE=\\"hidden\\" NAME=\\"edit\\" VALUE=\\"$propnum\\">";
print"<INPUT TYPE=\\"hidden\\" NAME=\\"action\\" VALUE=\\"upload\\">";
print"<INPUT TYPE=\\"hidden\\" NAME=\\"id\\" VALUE=\\"$id\\">";
print"<TABLE BORDER=\\"0\\" cellpadding=3>";
print"<TD>File: </TD>";
print"<TD><INPUT TYPE=\\"file\\" NAME=\\"img1\\"></TD>";
print"</TR>";
print"<TR>";
print"<TD COLSPAN=\\"2\\"><INPUT TYPE=\\"submit\\" VALUE=\\"Upload\\"></TD>";
print"</TR>";
print"</TABLE>";
print"</FORM>";
print "</center></td></tr></table>";
}
else
{
print "<CENTER><img src=\\"./pics/$image\\"</center><form action=\\"editcat.php\\" method=\\"post\\"><input type=\\"hidden\\" name=\\"id\\" value=\\"$id\\"><input type=\\"submit\\" value=\\"deleteimage\\" name=\\"Delete\\"></form><a href=\\"editcat.php?action=deleteimage\\">Delete This Image</a>";
}
}
?>
you could try removing the $link var from the mysql_query, also if u click the “delete this image” text link it doesnt pass an ID, which cause fetching cat details error, put &id=$id in The print statement at the end of the text link.