array_map显示mysql_real_escape_string()预计参数1 [英] array_map show mysql_real_escape_string() expects parameter 1
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select\">mysql_fetch_array()预计参数1是资源,在选择布尔给予
当我使用
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?
编辑:
如果我用
and if i use
array_walk_recursive($_POST, 'mysql_real_escape_string');
则显示
Warning: mysql_real_escape_string() expects parameter 2 to be resource, integer given in D:\xampp\htdocs\..\...\xyz.php on line 17
也请您告诉我,这两种方法上面有什么区别?
谢谢你在前进
please also tell me the difference above both method? Thank You in advance
推荐答案
我认为 $的要素之一_ POST
的确是一个数组,可视化是这样的:
I assume that one of the elements of $_POST
is indeed an array, visualised something like this:
print_r($_POST);
Array
(
...
'element' => Array
(
'subelement' => 'some value'
)
...
)
在 array_map
试图给 $的价值_ POST ['元素']
到 mysql_real_escape_string
,它抛出你描述的错误。
When array_map
tries to give the value of $_POST['element']
to mysql_real_escape_string
, it throws the error you describe.
您可以尝试虽然包裹的号召,沿着这条(未经测试)函数的内容:
You could try to wrap the call though, something along this (untested) function:
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);
这篇关于array_map显示mysql_real_escape_string()预计参数1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!