I'm getting a warning from PHP
:
PHP Warning: mysqli::real_escape_string() expects parameter 1 to be string, array given in ..
The code giving the warning is:
$saveData = array_map(array($connection, 'real_escape_string'), $saveData);
$saveData is decoded JSON taken from $_POST - typical dataset would be:
array(22) {
["quoteID"]=>
string(7) "GLY0YQ5"
["Inventory"]=>
array(0) {
}
["pickupLocation"]=>
string(15) "EPPING NSW 2121"
["dropOffLocation"]=>
string(17) "RICHMOND VIC 3121"
["pickupSuburb"]=>
string(6) "EPPING"
["pickupPostcode"]=>
string(4) "2121"
["pickupState"]=>
string(3) "NSW"
["dropoffSuburb"]=>
string(8) "RICHMOND"
["dropoffPostcode"]=>
string(4) "3121"
["dropoffState"]=>
string(3) "VIC"
["pickupLatitude"]=>
string(10) "-33.772549"
["pickupLongitude"]=>
string(10) "151.082365"
["dropoffLatitude"]=>
string(10) "-37.818587"
["dropoffLongitude"]=>
string(10) "144.999181"
["pickupDistance"]=>
string(1) "0"
["pickupAccess"]=>
string(1) "0"
["dropoffDistance"]=>
string(1) "0"
["dropoffAccess"]=>
string(1) "0"
["regionalLoading"]=>
string(1) "0"
["totalVolume"]=>
string(2) "39"
["totalDistance"]=>
string(3) "897"
["totalPrice"]=>
string(4) "3120"
}
My understanding is the issue is mysqli
expecting the first parameter to be the $connection
variable, which it actually is, it's just different to the regular mysqli
format because of the format required by array_map
.
Given the outcome desired is the real_escape
the entire array in one shot, and that the error
is just a warning
and is actually working, is there a better way to do this, and is it even necessary to make an adjustment?