Array_map show mysql_real_escape_string () expects parameter 1

Possible duplicate:
mysql_fetch_array () expects parameter 1 to be a resource, boolean is set to select

when i use

array_map('mysql_real_escape_string', $_POST);

it display

    Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in D:\xampp\htdocs\...\...\xyz.php on line 14

what is the reason after that?

EDIT:  and if I use

array_walk_recursive($_POST, 'mysql_real_escape_string');

then displayed

Warning: mysql_real_escape_string() expects parameter 2 to be resource, integer given in D:\xampp\htdocs\..\...\xyz.php on line 17

please tell me the difference above both methods? Thank you in advance

+3
source share
2 answers

I assume one of the elements $_POSTis really an array rendering something like this:

print_r($_POST);

Array
(
 ...
    'element' => Array
    (
        'subelement' => 'some value'
    )
 ...
)

When it array_maptries to pass a value $_POST['element']to mysql_real_escape_string, it produces the error you described.

, - () :

function recursive_escape(&$value) {
    if (is_array($value))
        array_map('recursive_escape', $value);
    else
        $value = mysql_real_escape_string($value);
}

array_map('recursive_escape', $_POST);
+9

, $_POST ?

:

<input type="text" name="value[]">

[] ? , $_POST.

var_dump $_POST , - .

, , mysql_real_escape_string . Cassy, ​​ .


, :

array_walk_recursive , , , array_map - .

(PHP . .)

+6

Source: https://habr.com/ru/post/1730787/


All Articles