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?
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
Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li
Quote:
Originally Posted by
lhungil
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')) {
???
??
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')) {
Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li
Quote:
Originally Posted by
lhungil
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).
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'])) {
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!
Re: PHP Warning: Invalid argument supplied for foreach() in update_product.php on li
Quote:
Originally Posted by
limelites
Should maybe be this?
Ahh, the beauty of typo's :P