resting Posted July 6, 2009 Share Posted July 6, 2009 Hi guys, I wrote the following codes and it seems to display well from the print_r statement. however there is this Warning: Invalid argument supplied for foreach() in *** on line 26 which i dont understand why its there. it is caused by this statement foreach($sel as $sel_product => $id) but all arguments supplied are valid to what i know. would be glad if someone here helps me out. thanks. The statements: if(is_array($_REQUEST)){ foreach ($_REQUEST as $sel){ foreach($sel as $sel_product => $id) { echo "Selected product:" . $sel_product. "<br>"; echo "Selected id:" . $id. "<br>"; } } } The print out: Array ( [Food] => Array ( [1] => 1 [2] => 4 ) [Drink] => Array ( [4] => 1 ) [phpSESSID] => s51v7i378hvp8im5u2smgbgo07 ) Selected product:1 Selected id:1 Selected product:2 Selected id:4 Selected product:4 Selected id:1 Warning: Invalid argument supplied for foreach() in *** on line 26 Quote Link to comment Share on other sites More sharing options...
joel24 Posted July 6, 2009 Share Posted July 6, 2009 you should use $_GET / $_POST instead of $_REQUEST. I don't know exactly how the script works, but I'm guessing not all of the $_REQUEST elements are arrays - hence the second foreach is causing an error.. try if(is_array($_REQUEST)){ foreach ($_REQUEST as $sel){ if (is_array($sel) { foreach($sel as $sel_product => $id) { echo "Selected product:" . $sel_product. "<br>"; echo "Selected id:" . $id. "<br>"; } } } } Quote Link to comment Share on other sites More sharing options...
resting Posted July 6, 2009 Author Share Posted July 6, 2009 hi, u're right! i forgot abt the Session id in $_REQUEST. thanks. i'll go figure out how to work my scripts again now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.