array_map() probably obvious mistake


Posted on 16th Feb 2014 07:03 pm by admin

The code below is part of a class to escape strings, but should also accept an array, using array_map() to do the job. Unfortunately, passing an array results in the original, unescaped array being returned - can't figure out why? If you uncomment the echo statement, it is outputting the correct escaped string for each element of the array, so the callback is definitely happening.

public function escape_str($str)
{
if (is_array($str))
{
array_map(array('MYSQL_DB','escape_str'),$str);
}
else
{
if (get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
if (!is_numeric($str)) {
$str = "'" . mysql_real_escape_string($str) . "'";
//echo $str.'<br />';
}
}
return $str;
}

Example:
$xt = array("' OR ''=''",'"abcdefg"');
print_r($db->escape_str($xt));

Outputs original array, not escaped!

Can anyone help with this? Thanks.

204 Like 21 Dislike
Previous php-forum Next php-forum
Other php-forum

question about header() security
is is safe to just use the header() function to redirect someone if they are, say, not logged in? or

array & querys help/advice.
Ok so here goes , I have a mysql database and basically here's what I need to do.

// foreach

my sql select id and then update problem.
I need to select some auto incremented ids out of a database and then use those id in a where statem

help with php
It's not displaying or pulling anything out of the database.


Code: <html><

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

PHP page is blank
Hi Everyone,

I have a site in which I am able to open the first PHP webpage in my browser but

Limiting uploaded file type
I am working on a simple upload script, and I need it to limit the allowed file type that is uploade

Generate multilayered array from string.
ok so i have a string that looks like this:
Code: [Select]blog:edit_all,delete_all|users:edit_all

single values into sql field
i have a form which i want the user to able to select multiple answers. But i want the answers to be

Using two $_POST Function / Switch () statements, second does not work.
Hi all. I’m new to php and am having a problem getting $_POST Function / switch () to work. I

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash