I use object oriented style for my mysql connection, but if I write this:
array_walk_recursive($_POST, array($mysqli, 'real_escape_string'));
I get this error:
Warning: mysqli::real_escape_string() expects exactly 1 parameter, 2 given
The fact is that mysqli::escape_string accept only 1 parameter:
string mysqli::escape_string ( string $escapestr )
I write:
$VAR = array();
$VAR = $_POST;
function escape_string($item, $key) {
$arr[$key] = $mysqli->real_escape_string($item);
}
array_walk_recursive($VAR, 'escape_string');
And I get this error:
Fatal error: Call to a member function real_escape_string() on a non-object
You need to pass a string as the second argument, not an array:
function escape_string($item, $key) {
// Echo them out (using procedural mysqli)
echo mysqli_real_escape_string($item);
// or collect them in an array (using OOP mysqli)
$arr[$key] = $mysqli->real_escape_string($item);
}
array_walk_recursive($_POST, 'escape_string');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With