Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorjay0316
    • CommentTimeJan 24th 2008 edited
     permalink
    Hi,

    We are getting the following message when we try to run this loop: Warning: Invalid argument supplied for foreach() in /var/www/products/product_admin/item_setup_processor.php on line 167

    We just moved the page from yahoos webhosting running php4 to an inhouse server running php5. I tried running a count on the array and it says there is one element in there, which would be correct. So, I'm at a loss for ideas. It was working just fine on yahoos servers.

    Any ideas?

    $options4 = array($category_ex);
    echo count($options4); //results in 1 meaning the array isn't empty
    foreach( $category_ex as $key => $value){
    //posts id of existing categories selected
    mysql_select_db("coas50", $con);
    $cat_query="SELECT Cat_ID FROM coas50.pro_sub_categories WHERE Sub_ID='$value'";
    $result=mysql_query($cat_query) or die(mysql_error());
    while ($row=mysql_fetch_array($result)) {

    $cat_id=$row["Cat_ID"];
    }
    $sql="INSERT INTO coas50.pro_categories_look_up SET Item_ID='$user_id', Cat_ID='$cat_id', Sub_Cat_ID='$value'";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    //echo "1 Category added

    ";
    //echo "Cat ID: $cat_id, Sub Cat ID: $value
    ";
    }
    •  
      CommentAuthorJJenZz
    • CommentTimeJan 28th 2008
     permalink
    try "print_r($options4);" instead of "echo count($options4);".

    You will find that the array looks like this:
    Array ( [0] => );
    This means the count is 1 but the value is empty.

    Whatever sets the value of $category_ex isn't setting it properly.
Add your comments
    Username Password
  • Format comments as (Help)