JSON to PHP, then foreach?

DRAGGON

New Member
I send a valid JSON string to my PHP page from jQueryscript:\[code\]var data = 'http://stackoverflow.com/questions/2073408/{"data":[ { "id":"12", "checked":"true" },{ "id":"4", "checked":"false" },{ "id":"33", "checked":"false" } ]}';$.post ("page.php", { data_input:data }, function (data) { // code});\[/code\]Once I get the data in my PHP page, I parse it with the \[code\]json_decode\[/code\] method, and then try to use it in a \[code\]foreach\[/code\] statement created for a \[code\]PDO\[/code\] query:\[code\]<?php$data_input = json_decode ($_REQUEST['data_input'], true);$sql = "UPDATE my_table SET user_enabled = :checked WHERE node_prop_id = :id";$stmt = $dns->prepare ($sql);foreach ($data_input as $data) { $ok = $stmt->execute ($data); $num = $stmt->rowCount ();} if ($ok) return 1;else return 0;?>\[/code\]This returns me the error:\[quote\] PHP Warning: Invalid argument supplied for foreach() in /home/.../page.php on line XX\[/quote\]Can I find a way to use my JSON data in the \[code\]foreach\[/code\] statement?
 
Back
Top