How to solve "notice array to string conversion in C" error in php and javascript? -
so trying send "id" of selected row in datatable in javascript php page delete database.
var ids = $.map(table.rows('.selected').data(), function (item) { return item[0] }); the variable "ids" sent post method
$.post( "deleterow.php", { v1: ids });
but didn't worked try see response post method , says "notice array string conversion in c on line ... " line of php page writing delete query
$id = $_post["v1"]; $query = "delete `package` `id` = '$id'"; the whole php page works fine when trying other values.
because send array here:
$.post( "deleterow.php", { v1: ids }); so v1 contains array of elements. in php code treat single element:
$id = $_post["v1"]; hence notice array string conversion.
if send array of elements, have array , treat array. create correct sql string should append each id, this:
$ids = json_decode($_post["v1"]); $query = "delete `package` where"; $first = true; foreach ($ids $id) { if ($first) { $first = false; } else { $query += " or"; } $query += " `id` = '$id'" } this way loop array , append id = id each array element.
now, this important, code prone sql injection, bad security problem. read more info this: how can prevent sql injection in php?
Comments
Post a Comment