RE: error when trying to delete a record

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Paul Waring [mailto:paul@xxxxxxx] 

> On Mon, Jul 11, 2005 at 03:25:33PM +0100, Mark Rees wrote:
> > with no single quotes round it. Putting quotes round 
> > integer values is counter-intuitive - is it necessary 
> > in some cases?
> 
> If the field is a numeric type (e.g. INT) as opposed to 
> numeric data being stored in a character field (e.g. a 
> telephone number) then it is not only unnecessary to quote 
> the value, it's also incorrect useage of SQL, although 
> you'd probably get away with it in most database systems.

I agree. What's best is to ensure the val is of the proper type before
sending it to the db. Try casting it first; if the value is blank, it'll
cast as 0 (though that may not be optimal, either, if your record could
be 0):

$query = "DELETE FROM sheet1 WHERE id = " . (int)$id;

Also probably best to check if it's empty, something such as:

if (!empty($id)) {
	$query = 'DELETE FROM sheet1 WHERE id = ' . (int)$id;
} else {
	echo 'Argument $id was empty';
}

HTH!

-- 
Mike Johnson             Smarter Living, Inc.
Web Developer            www.smartertravel.com
mike@xxxxxxxxxxxxxxxxx   (617) 886-5539

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux