Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Posts
    2,124
    Plugin Contributions
    0

    Default PHP Warning: Invalid argument supplied for foreach() in update_product.php on line 2

    I've noticed we're getting the following error each time we use the update button when editing products:

    PHP Warning: Invalid argument supplied for foreach() in /admin/includes/modules/update_product.php on line 294

    It point to this section:

    PHP Code:
        $sql_del "delete from product_ebay_shipping_methods where shipping_type = 'International' and products_id = "$products_id;
        
    $db->Execute($sql_del);
         
        if (
    $_POST['shipping_imethod1'] != '') {
        
            
    $strLocation "";
    HERE>>>    foreach($_POST['shipping_ilocation1'] as $nam=>$val) {
                
    $strLocation .= "'" $val "'" ",";
            }    
            if (
    $strLocation != '') {
                
    $strLocation substr($strLocation,0,strlen($strLocation)-1);
            }
            
            
    $sql_arr_ins = array('products_id' => $products_id,
                                 
    'shipping_type' => 'International',
                                 
    'shipping_service' => $_POST['shipping_imethod1'],
                                 
    'shipping_cost' => $_POST['shipping_icost1'],
                                 
    'shipping_add_cost' => $_POST['shipping_iadd_cost1'],
                                 
    'shipping_location' => $strLocation);    
            
    zen_db_perform("product_ebay_shipping_methods"$sql_arr_ins);
        } 
    Can anyone see anything obviously wrong with the coding, or can anyone think what's maybe causing it?

  2. #2
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,247
    Plugin Contributions
    7

    Default Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li

    You are not checking to see if $_POST['shipping_ilocation1') is an array before passing it to foreach.

    Example:
    PHP Code:
        if (isset($_POST['shipping_imethod1']) && is_array($_POST['shipping_ilocation1')) { 
    Feel free insert your preference for the first check (just one to ensure the index exists - some checks do more than others): array_key_exists('shipping_imethod1', $_POST), isset($_POST['shipping_imethod1']), zen_not_null($_POST['shipping_imethod1']), $_POST['shipping_imethod1'] !== null, etc
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhngl : Plugin / Module Tracker

  3. #3
    Join Date
    Jan 2009
    Posts
    2,124
    Plugin Contributions
    0

    Default Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li

    Quote Originally Posted by lhungil View Post
    You are not checking to see if $_POST['shipping_ilocation1') is an array before passing it to foreach.

    Example:
    PHP Code:
        if (isset($_POST['shipping_imethod1']) && is_array($_POST['shipping_ilocation1')) { 
    Feel free insert your preference for the first check (just one to ensure the index exists - some checks do more than others): array_key_exists('shipping_imethod1', $_POST), isset($_POST['shipping_imethod1']), zen_not_null($_POST['shipping_imethod1']), $_POST['shipping_imethod1'] !== null, etc
    I'm sorry, I'm not too good with PHP. Do you mean I should replace this:
    PHP Code:
        foreach($_POST['shipping_ilocation1'] as $nam=>$val) { 
    with this:
    PHP Code:
    if (isset($_POST['shipping_imethod1']) && is_array($_POST['shipping_ilocation1')) { 
    ???

    ??

  4. #4
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,247
    Plugin Contributions
    7

    Default Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li

    Replace:
    PHP Code:
    if ($_POST['shipping_imethod1'] != '') { 
    With:
    PHP Code:
    if (isset($_POST['shipping_imethod1']) && is_array($_POST['shipping_ilocation1')) { 
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhngl : Plugin / Module Tracker

  5. #5
    Join Date
    Jan 2009
    Posts
    2,124
    Plugin Contributions
    0

    Default Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li

    Quote Originally Posted by lhungil View Post
    Replace:
    PHP Code:
    if ($_POST['shipping_imethod1'] != '') { 
    With:
    PHP Code:
    if (isset($_POST['shipping_imethod1']) && is_array($_POST['shipping_ilocation1')) { 
    Replace:
    PHP Code:
    if ($_POST['shipping_imethod1'] != '') { 
    With:
    PHP Code:
    if (isset($_POST['shipping_imethod1']) && is_array($_POST['shipping_ilocation1')) { 
    .causes a syntax error (according to Dreamweaver).

  6. #6
    Join Date
    Jan 2009
    Posts
    2,124
    Plugin Contributions
    0

    Default Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li

    Should maybe be this?

    PHP Code:
    if (isset($_POST['shipping_imethod1']) && is_array($_POST['shipping_ilocation1'])) { 

  7. #7
    Join Date
    Jan 2009
    Posts
    2,124
    Plugin Contributions
    0

    Default Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li

    Well, just uploaded it and it seems to do the trick... no more myDEBUG-000000000000.log's when I update or add new products.... thank you!

  8. #8
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,247
    Plugin Contributions
    7

    Default Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li

    Quote Originally Posted by limelites View Post
    Should maybe be this?
    Ahh, the beauty of typo's
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhngl : Plugin / Module Tracker

 

 

Similar Threads

  1. Replies: 5
    Last Post: 29 Jun 2011, 04:16 AM
  2. Debug: USPS.php PHP Warning: Invalid argument supplied for foreach()
    By divinelighting in forum Addon Shipping Modules
    Replies: 2
    Last Post: 11 Jun 2011, 03:17 AM
  3. Help receiving: Warning: Invalid argument supplied for foreach()
    By kateoeight in forum General Questions
    Replies: 9
    Last Post: 1 May 2007, 09:28 PM
  4. Warning: Invalid argument supplied for foreach
    By harlyman in forum General Questions
    Replies: 9
    Last Post: 23 Aug 2006, 11:39 AM
  5. Replies: 7
    Last Post: 31 Jul 2006, 04:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •