Zen Cart Logo
Forums / General Questions / PHP Warning: Undefined array key "products_id"

PHP Warning: Undefined array key "products_id"

Views: 875

Results 1 to 6 of 6
21 Jun 2025, 7:45 AM
#1
tamya avatar

tamya

Zen Follower

Join Date:
Feb 2007
Posts:
336
Plugin Contributions:
0

PHP Warning: Undefined array key "products_id"

Zen Cart 2.1.0
PHP Version: 8.0.30 (Zend: 4.0.30)

I am using the following code to show reviews on the products page (as suggested by Lat9)
```
$review_status = " AND r.status = 1"; $reviews_query_raw = "SELECT r.reviews_id, rd.reviews_text, r.reviews_rating, r.date_added, r.customers_name
FROM " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd
WHERE r.products_id = :productsID
AND r.reviews_id = rd.reviews_id
AND rd.languages_id = :languagesID " . $review_status . "
ORDER BY r.reviews_id desc";
$reviews_query_raw = $db->bindVars($reviews_query_raw, ':productsID', $_GET['products_id'], 'integer');
$reviews_query_raw = $db->bindVars($reviews_query_raw, ':languagesID', $_SESSION['languages_id'], 'integer');
$reviews_split = new splitPageResults($reviews_query_raw, MAX_DISPLAY_NEW_REVIEWS);
$reviews = $db->Execute($reviews_split->sql_query);
$reviewsArray = array();
while (!$reviews->EOF) {
$reviewsArray[] = array('id'=>$reviews->fields['reviews_id'],
'customersName'=>$reviews->fields['customers_name'],
'dateAdded'=>$reviews->fields['date_added'],
'reviewsText'=>$reviews->fields['reviews_text'],
'reviewsRating'=>$reviews->fields['reviews_rating']);
$reviews->MoveNext();

">
I get the PHP warning below
> [21-Jun-2025 07:32:02 UTC] Request URI: /index.php?main_page=product_info&products_id=250, IP address: 45.224.23.91, Language id 1
> #1 require(/includes/modules/pages/product_info/header_php.php) called at [/index.php:35]
> --> PHP Warning: Undefined array key "products_id" in /includes/modules/pages/product_info/header_php.php on line 37.

Line 37 is 
 $reviews_query_raw = $db->bindVars($reviews_query_raw, 'productsID', $_GET['products_id'], 'integer');

This warning occurs when a user or a bot try to access a discontinued item, in this case it is an item with the products_id=250.
Is there a way to get around this? Thanks.
21 Jun 2025, 12:08 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,108
Plugin Contributions:
56

Re: PHP Warning: Undefined array key "products_id"

Perhaps changing $_GET['products_id'] to $products_id_current on line 37, but I don't see where $_GET['products_id'] disappeared to ... since it's part of the URL included in that log.

22 Jun 2025, 8:45 PM
#3
tamya avatar

tamya

Zen Follower

Join Date:
Feb 2007
Posts:
336
Plugin Contributions:
0

Re: PHP Warning: Undefined array key "products_id"

lat9:

Perhaps changing $_GET['products_id'] to $products_id_current on line 37, but I don't see where $_GET['products_id'] disappeared to ... since it's part of the URL included in that log.

Thanks Cindy, changed, 3 hours later and testing with urls like */index.php?main_page=product_info&products_id=250 no log warning. Thanks.

*

7 Jul 2025, 6:10 PM
#4
nldav avatar

nldav

New Zenner

Join Date:
Jan 2005
Posts:
55
Plugin Contributions:
0

Re: PHP Warning: Undefined array key "products_id"

lat9:

don't see where $_GET['products_id'] disappeared to ... since it's part of the URL included in that log.

$product_info = new Product($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0));
if ($product_info->exists() && $current_page !== $product_info->get('info_page')) {
    zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params()));
}
function zen_get_all_get_params($exclude_array = array())
{
    if (!is_array($exclude_array)) $exclude_array = array();
    $exclude_array = array_merge($exclude_array, array('main_page', 'error', 'x', 'y', 'cmd'));

main_page is excluded

8 Jul 2025, 2:29 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,108
Plugin Contributions:
56

Re: PHP Warning: Undefined array key "products_id"

nl2dav:

$product_info = new Product($products_id_current = (!empty($_GET['products_id']) ? (int)$_GET['products_id'] : 0));
if ($product_info->exists() && $current_page !== $product_info->get('info_page')) {
zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params()));
}

> 
> ```
function zen_get_all_get_params($exclude_array = array())
{
    if (!is_array($exclude_array)) $exclude_array = array();
    $exclude_array = array_merge($exclude_array, array('main_page', 'error', 'x', 'y', 'cmd'));

main_page is excluded
I'm not sure where that code's from, but I don't think it's got anything to do with the log identified in the first post of this thread.

8 Jul 2025, 4:12 PM
#6
nldav avatar

nldav

New Zenner

Join Date:
Jan 2005
Posts:
55
Plugin Contributions:
0

Re: PHP Warning: Undefined array key "products_id"

it does though, the first section is from /includes/modules/pages/product_info/header_php.php (mentioned in the log)

/includes/modules/pages/product_info/header_php.php uses the function zen_get_all_get_params (/includes/functions/functions_general_shared.php) but gets disregarded because main_page /index.php?main_page=product_info&products_id=250 is in the excluded array

if ($product_info->exists() && $current_page !== $product_info->get('info_page')) {
    zen_redirect(zen_href_link($product_info->get('info_page'), zen_get_all_get_params()));
}

there is a redirect with zen_get_all_get_params but this ($get_url) is empty because of main_page

function zen_get_all_get_params($exclude_array = array())
{
    if (!is_array($exclude_array)) $exclude_array = array();
    $exclude_array = array_merge($exclude_array, array('main_page', 'error', 'x', 'y', 'cmd'));

right? almost starting to doubt own research