Delete... [status: solved!]
Posted: Sun Oct 09, 2005 9:14 pm
Ok before I added that delete and editing features... it was working fine... but whenever I click on "delete" link to delete a picture that i was viewing (only when I'm logged in)... I get this error:
I have absolutely no idea what I did wrong. :S Of course, the url will be view.php?pix=image.jpg?a=del or view.php?pix=image.jpg?a=edit for actions to be performed.. whenever I use a variable in there, I get query error
but when a isn't in the url, I dont get error. *scratches her head* Also deleting an image doesn't work at all either... but I didn't get any errors except "Error performing query!" mentioned earlier. *scratches her head again*
my script is
Code: Select all
Error performing query!my script is
Code: Select all
<?php
session_start();
$session = $_SESSION['auth'];
if ($session == "yes")
{
$menu = "yes";
}
else
{
$menu = "no";
}
?>
<html><title>Dm7.net :: Viewing</title>
<body>
<?php
#########################################
# Admin Gallery System #
# view.php #
#########################################
include("gallery.css");
include("links.css");
include("functions_main.inc.php");
include("fields_login.inc.php");
$table = "art";
$pix = $_REQUEST['pix'];
//is a (action variable) set?
if (isset($_REQUEST['a']))
{
//is a = del?
if (($_REQUEST['a'] == "del") && ($_SESSION['auth'] == "yes"))
{
if (isset($pix))
{
Connect_to_db("Vars.inc.php");
$sql = "DELETE FROM $table WHERE name = '$pix'";
mysql_query($sql) or die("Error performing query - could not delete!". mysql_error());
?><font color="red"><h2><center>This picture has been deleted!</center></font></h2>
<center><?php loginmenu(); ?></center><?php ;
mysql_close();
exit();
}
else
{
echo "No picture to delete from!";
}
}
//is a = edit?
if (($_REQUEST['a'] == "edit") && ($_SESSION['auth'] == "yes"))
{
if (isset($pix))
{
echo "Editing feature isn't available yet.";
exit();
}
else
{
echo "No picture to edit from!";
}
}
}
//checks if pix variable is set.. if not, an error msg is given.
if (!isset($pix)) {
?>
<font color="red"><h2><center>Error obtaining a requested picture!</center></h2>
</font> <?php }
// Connects to db and generates the result
else {
Connect_to_db("Vars.inc.php");
$sql = "SELECT * FROM $table WHERE name ='$pix'";
$result = mysql_query($sql);
if ($row = mysql_fetch_assoc($result)) {
printf("<div align=\"center\" class=\"title\">\"%s\"</div>\n <table border='0' align='center'><tr><td><img src='%s'></td></tr><tr><td class=\"titletb\"><span class='pink'><b>Title:</b></span> %s</td></tr><tr><td class=\"titletb\"><span class='pink'><b>Date:</b></span> %s</td></tr><tr><td class=\"titletb\"><span class='pink'><b>Description/Comment:</b></span> %s</td></tr></table>",$row['title'],$row['image'],$row['title'],$row['date'],$row['comment']);
}
else { echo "<font color=\"red\"><h2><center>Error performing query!<br>" . mysql_error() . "</center></h2></font>"; }
mysql_close();
}
?><br>
<div align="center" class="titletb"><?php
loginmenu();
function loginmenu()
{
global $menu, $menuloginview, $pix;
if($menu == "yes")
{
$edit = "<a href='view.php?pix=". $pix ."?a=edit'>Edit</a> | ";
$del = "<a href='view.php?pix=". $pix ."?a=del'>Delete</a> | ";
echo $edit ." ". $del;
foreach($menuloginview as $key => $value)
{
if ($key == "logout")
{
echo $value;
}
else
{
echo $value ." | ";
}
}
}
}
?></div>
<p align="center" class="pink"><b>After viewing, close your window to return to the gallery page.</b></p>
</body>
</html>