RE: [PHP] Re: Trying to delete
On Wed, 14 Aug 2002, [iso-8859-1] César Aracena wrote: > Thanks. I must apology as I made a mistake when writing the incoming > variable's name. I had it wrong so it would pass the variable but the > incoming script was looking for a variable that wasn't passed. In the > meantime, and now that I correct that, I'm still comparing artid to > '$artid' (with single quotes) and it does it well... it is an int(4) > field and now that you mention it... how is it possible? MySQL lets you compare numbers and strings pretty liberally: mysql> create table foo (x int, y double); Query OK, 0 rows affected (0.02 sec) mysql> insert into foo values (1, 3.1415); Query OK, 1 row affected (0.09 sec) mysql> select * from foo where x = '1'; +--++ | x| y | +--++ |1 | 3.1415 | +--++ 1 row in set (0.01 sec) mysql> select * from foo where y like '3.14%'; +--++ | x| y | +--++ |1 | 3.1415 | +--++ 1 row in set (0.00 sec) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Trying to delete
Thanks. I must apology as I made a mistake when writing the incoming variable's name. I had it wrong so it would pass the variable but the incoming script was looking for a variable that wasn't passed. In the meantime, and now that I correct that, I'm still comparing artid to '$artid' (with single quotes) and it does it well... it is an int(4) field and now that you mention it... how is it possible? C. > -Original Message- > From: David Robley [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, August 14, 2002 12:47 AM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: [PHP] Re: Trying to delete > > In article <01c2433c$e2e3e4c0$e5c405c8@gateway>, [EMAIL PROTECTED] > 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"; > > echo ""; > > echo " > value=3D\"Back to Edition\">"; > > echo ""; > > } > > else if ($result) > > { > > echo "The Picture was deleted sucsesfully"; > > echo ""; > > echo " > value=3D\"Back to Edition\">"; > > echo ""; > > } > > } > > > > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Trying to delete
In article <01c2433c$e2e3e4c0$e5c405c8@gateway>, [EMAIL PROTECTED] 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"; > echo ""; > echo " value=3D\"Back to Edition\">"; > echo ""; > } > else if ($result) > { > echo "The Picture was deleted sucsesfully"; > echo ""; > echo " value=3D\"Back to Edition\">"; > echo ""; > } > } > > 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php