note 47888 added to function.mysql-escape-string
| From: | hexaofh3xadotcom at osu1 dot php dot net | Date: | Fri, 03 Dec 2004 22:55:14 +0000 |
| Subject: | note 47888 added to function.mysql-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81343@lists.php.net to get a copy of this message | ||
i´ve come with this handy function to apply to variables (if an array, non multi-dimesional only)
everytime i need to insert them in the db. it checks if magic_quotes are enabled, to not re-add
slashes.
<?php
function slashes(&$var) {
if (is_array($var)) {
if (!get_magic_quotes_gpc()) {
foreach ($var as $chave => $valor) {
$var[$chave] = mysql_escape_string($valor);
}
}
}
else {
mysql_escape_string($var);
}
return true;
}
?>
example:
slashes($_POST);
mysql_query(...);
----
Manual Page -- http://www.php.net/manual/en/function.mysql-escape-string.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47888
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47888&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47888&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47888&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47888&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47888&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47888&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47888&report=yes
Search -- http://master.php.net/manage/user-notes.php