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.

No comments posted yet

Your Answer:

Login to answer
204 Like 21 Dislike
Previous forums Next forums
Other forums

extending tidy
I have problem with type-hinting and extending tidy. This code creates error:
Code: class cMyTidy

Character increment
Hi,

I am facing a scenario like above,but in my case i want to show up like Col A,Col B etc..

How to create a static html menu from a database
Hi,

I have built a small cms which allows me to create simple html pages and then upload them

Loop column after 2 results
Hello All.

Here is what I have:

Client ID Company name Clien

Inserting into MySQL Newbie
Hi ive got a slight problem where ive made a simple web form where the customer inserts the ammount

How to make a mail Form secure?
I want to create an email Form on my web site. How can I make the Form secure so the submitted info

SESSION question
I am building an application , a directory for auctions.
For SEO i made a script which copies a p

Need help adding a timestamp to my filename/variable
Hello,

I'm kind of stupid when it comes to php and I need a tiny bit of help. I've got a f

PHP and Javascript
Hello Everyone,

I have a page that needs a javascript code to be written between PHP code but

post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu

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