I've been working on this script all day with no luck at all. I have to successfully test both parts of this script in order to finish this project. I haven't tested the delete part yet, because I can't get the update part to work. I just can't figure out why this will not update the database.
[PHP]<?php
include("includes/dbconnect.php");
if(!isset($cmd))
{
$result = mysql_query("select * from $table order by title");
while($r = mysql_fetch_array($result))
{
$id = $r["id"];
$title = stripslashes($r["title"]);
echo "
<tr>
<td width='20%' align='right'>ID#: </td>
<td>$id</td>
</tr>
<tr>
<td width='20%' align='right'>Picture Title: </td>
<td>$title</td>
</tr>
<tr>
<td width='20%' align='right'>Picture File Name: </td>
<td>$image_name</td>
</tr>
<tr>
<td width='20%' align='right'>[ <a href='edit_picture.php?cmd=edit&id=$id'>Edit</a> ]</td>
<td>[ <a href='edit_picture.php?cmd=delete&id=$id'>Delete</a> ]</td>
</tr>
<tr><td colspan='4' width='100%' style='border-top: 1px solid #666'> </td></tr>
";
}
}
?>
</table>
<?php
echo "<h3>Edit a Picture</h3>";
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM $table WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<center>
<table width="95%" cellspacing="0" cellpadding="3" border="0">
<tr><td>
<form action="edit_picture.php" method="post">
<input type="hidden" name="id" value="<?php echo $myrow['id'] ?>">
Picture Title:<br>
<input type="text" name="title" VALUE="<?php echo stripslashes($myrow['title']) ?>" size="55"><br><br>
Picture Description:<br>
<TEXTAREA name="desc" ROWS=2 COLS=70 wrap=virtual><?php echo stripslashes($myrow['desc']) ?></TEXTAREA><br><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
</td>
</tr>
</table>
</center>
<?php
}
?>
<?php
if ($_POST["$submit"])
{
$title = addslashes($_POST['title']);
$desc = addslashes($_POST['desc']);
$sql = "UPDATE $table SET title='$title', desc='$desc' WHERE id=$id";
$result = mysql_query($sql);
echo "<br><br><p align='center'><span style='color:red'>Information updated.</span><br><br><a href='edit_picture.php'>Edit another Picture</a></p>";
}
}
?>
<?php
if($_GET["cmd"]=="delete")
{
$image_name = $_GET["image_name"];
$photo_dir = ('/mysite.com/gallery/image_uploads/');
$thumb_dir = ('/mysite.com/gallery/thumb_uploads/');
unlink($photo_dir.$image_name);
unlink($thumb_dir.$image_name);
$sql = "DELETE FROM $table WHERE image_name=$image_name";
$result = mysql_query($sql);
echo "<br><br><p align='center'><span style='color:red'><b>The Picture has been Deleted!<br><br>";
}
?>[/PHP]