PHP foreach error “Invalid argument supplied for foreach”

ぃ、小莉子 提交于 2020-01-03 05:23:13

问题


I was previously using this code and it worked perfectly fine, but when I put it on another server just now it started freaking out, I am passing a JSON object to a PHP file and traversing through it, the foreach I used seemd to work fine, but now I get "Invalid argument supplied for foreach",

PHP:

<?php
    $json = $_POST['systems']; 
    $uid = $_POST['uid'];
    $test = json_decode($json, true); 

    mysql_connect('localhost','user','password') or die(mysql_error());
    mysql_select_db('products') or die(mysql_error());

    //insert the suppliers products into the database
    foreach($test as $key){
        $query = mysql_query("INSERT INTO suppliersProducts (product_id, supplier_id) VALUES('".$key['value']."', '".$uid."' ) ") or die(mysql_error());
    }

    echo $uid;
?>

Everything was working fine on my localhost, so I have NO idea why it is bombing out like this, I would really appreciate any help or insight into this problem, as I need to solve it ASAP!

Thanx in advance!

来源:https://stackoverflow.com/questions/3707205/php-foreach-error-invalid-argument-supplied-for-foreach

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!