PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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*
Ok I echoed $sql... still got performing query error that i mentioned earlier.. it didn't show the echo at all (I just added echo at where $sql with delete request is). *scratches her head again :S*
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 ;
echo $sql;
mysql_close();
exit();
That's because the die() function is being called, put the echo $sql; line before mysql_query() or even change the die() to die(mysql_error() . " -- $sql");
...which is way later at the bottom where it calls the picture and other related information for viewing ??? (but it works when I don't use a variable in the url???).
the code I have right now with die(); replaced is..
Unless you've only done a partial copy of the displayed error, that doesn't appear anywhere in the code you have posted. There is a similar string in your code posted, but not exactly the same. Maybe the error is happening elsewhere?
Connect_to_db("Vars.inc.php");
$sql = "SELECT * FROM $table WHERE name ='$pix'";
// LET'S SEE WHAT YOUR QUERY REALLY IS
echo "SQL=$sql<br/>";
$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();
}
My guess is that the query is successful (so no mysql_error()) but is not returning any rows because there is no match for the where clause. You should check "numrows". There are really three conditions for a SELECT: rows returned, not matches found, error.