Re: Trying to delete
| From: | David Robley | Date: | Wed, 14 Aug 2002 03:47:26 +0000 |
| Subject: | Re: Trying to delete | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-db+get-21133@lists.php.net to get a copy of this message | ||
In article <000001c2433c$e2e3e4c0$e5c405c8@gateway>, icaam@icaam.com.ar
says...
> Hi all.
>
> I have a small problem here. I have this full-PHP site working with a
> MySQL db and came to a dead road when trying to delete a record from it
> from the Administrator's page. I have PHP to make this decision after
> the Administrator selected the record to delete and answered YES to the
> =BFAre you sure...? The last part will pass a hidden value of $editpic
> which tells the deleting script which artid to delete from the db. This
> is the code that does the deletion:
>
> else if ($deleteyes)
> {
> $query =3D "DELETE FROM saav_arts WHERE artid =3D '$editpic' LIMIT
> 1";
> $result =3D mysql_query($query) or die (mysql_error());
>
> if (!$result)
> {
> echo "The Picture could NOT be deleted<br>";
> echo "<form action=3D\"".$PHP_SELF."\"
> method=3D\"post\">";
> echo "<input type=3D\"submit\" name=3D\"cancel\"
> value=3D\"Back to Edition\">";
> echo "</form>";
> }
> else if ($result)
> {
> echo "The Picture was deleted sucsesfully<br>";
> echo "<form action=3D\"".$PHP_SELF."\"
> method=3D\"post\">";
> echo "<input type=3D\"submit\" name=3D\"cancel\"
> value=3D\"Back to Edition\">";
> echo "</form>";
> }
> }
>
> Cesar Aracena
> CE / MCSE+I
You have made some wrong assumptions in your code here; it is quite
possible that $result may be true but no entries have been deleted. You
perhaps should look at the possibility of testing mysql_affected_rows to
determine whether any rows have been updated/deleted.
WHERE artid = '$editpic'
implies that you expect artd to be a text field of type char or
varchar because you have enclosed the value that you are testing in single
quotes; if artid is in fact an integer type, this query will not affect
any rows, as the text value will never match an integer field value.
--
David Robley
Temporary Kiwi!
Quod subigo farinam