note 34127 added to function.mysql-real-escape-string
| From: | php-general at lists dot php dot net | Date: | Wed, 16 Jul 2003 19:18:27 +0000 |
| Subject: | note 34127 added to function.mysql-real-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52223@lists.php.net to get a copy of this message | ||
It should also be noted that escaping the data is a useless precaution unless you encapsulate ALL
submitted fields in quotation marks, including suspected numeric data. MySQL does not force you to
wrap your numbers in quotes, but it MUST be done to keep users from injecting code.
$new_num = $_POST['new_num'];
// SECURITY RISK
mysql_query("UPDATE user_info SET icq_num=$new_num WHERE my_num=1");
// better
mysql_query("UPDATE user_info SET icq_num='$new_num' WHERE
my_num='1'");
It is actually better to use option 2 anyway because MySQL takes longer to process unquoted
arguments in some cases. A good example is when you do a search against a character field using a
non-quoted number, much like the first example above (no idea why though).
This is correct as of MySQL 4.0.13.
----
Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34127
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34127&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34127&report=yes