problem in recorset that seems temporary

problem in recorset that seems temporary

am 25.01.2008 17:35:59 von Ruprecht Helms

Hi,

I have a problem that confuse me a little bit. When I want to delete a
picture by giving the id-value in the URL I get the following error:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL
result resource in
/opt/lampp/htdocs/pferdeservice_karle/galerie_delete.php on line 81


On clicking the relodebutton on the browser I get no error and the
deletion of the recordset seems to be not executed. When I don't reload
the page and change to view the pictureresults the recordset have been
deleted. But I don't know why I get the warning-message.

Attached the code.

Regards,
Ruprecht
http://www.rheyn.de

----------------------------------------------------


"http://www.w3.org/TR/html4/loose.dtd">




























Bildergalerie







Quicklinks





FAQ

News






News bearbeiten

News löschen







Galerie löschen


mysql_connect("localhost","root");

$result=mysql_db_query("pferdeservice-karle","SELECT * FROM Galerie
WHERE ID=$id");

$zahl = mysql_num_rows($result);
echo "Zahl vorhandener Bilder ".$zahl;
echo mysql_error();

while($row = mysql_fetch_object($result))
{
$galerie_id=$row->ID;
$result=mysql_db_query("pferdeservice-karle","DELETE FROM
Galerie_kultur WHERE GalerieID=$id");
}
$result=mysql_db_query("pferdeservice-karle","DELETE FROM Galerie WHERE
ID=$id");
echo mysql_error();
?>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: problem in recorset that seems temporary

am 25.01.2008 19:26:35 von krister.karlstrom

Hi!

I did not quite get the point here, but maybe that's not needed to solve
the problem... :-)

First of all, you seem to have enabled the register_global setting,
since I can't see from where the parameter $id is posted. Use the $_GET
or $_POST superglobal array instead. Take big care of input filtering
also and do not put "dirty" data directly into your query.

Second, the function mysql_db_query() has been deprecated for a long
time now, use mysql_select_db() and mysql_query() instead.

I think your problem is in your while-loop:

You loop over the result set $result and fetch the row as an object.
Then you execute a delete statement and at the same time overwriting
your previous result set $result, thus you will break the loop with an
error that the provided parameter is not a result set.

I also guess you have a typo in your last statement where you (probably)
try to delete the gallery. I guess that you maybe want to use the
variable $galerie_id..? Well, I can't tell without any more information
about your application.

Greetings,
Krister Karlström, Helsinki, Finland

Ruprecht Helms wrote:

> while($row = mysql_fetch_object($result))
> {
> $galerie_id=$row->ID;
> $result=mysql_db_query("pferdeservice-karle","DELETE FROM
> Galerie_kultur WHERE GalerieID=$id");
> }
> $result=mysql_db_query("pferdeservice-karle","DELETE FROM Galerie WHERE
> ID=$id");
> echo mysql_error();

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php