note 49057 added to function.mysql-real-escape-string
| From: | manderson at dsrglobal dot com | Date: | Sat, 15 Jan 2005 17:36:50 +0000 |
| Subject: | note 49057 added to function.mysql-real-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83332@lists.php.net to get a copy of this message | ||
The quote_smart() function in the "Best Practice" section does not quote any value which
is all numeric. This will drop all zero's from the the lefthand side of a string. While this is
intended to simplify the query string when storing numeric values this has a negative effect when
trying to store strings which just so happen to be all digits. For instance some zip codes have one
or more zero's on the lefthand side, and an MD5 hash may contain all numeric characters and the
lefthand characters can be zero's. In these cases the lefthand zero's will be dropped.
I would simply drop the is_numeric() check. There's no reason to not quote numeric values.
<?php
// bad query created using the quote_smart() function
$qs = "UPDATE tbl SET zipcode=" . quote_smart('01234');
// UPDATE tbl SET zipcode=1234
// acceptable query created after dropping the is_numeric() check
$qs = "UPDATE tbl SET number=" . quote_smart('01234');
// UPDATE tbl SET number='01234'
?>
----
Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49057
Delete -- http://master.php.net/manage/user-notes.php?action=delete+49057&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49057&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+49057&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+49057&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+49057&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+49057&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49057&report=yes
Search -- http://master.php.net/manage/user-notes.php