Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2007
    Posts
    327
    Plugin Contributions
    0

    Default 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)
    Code:
      $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.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,973
    Plugin Contributions
    96

    Default 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.

  3. #3
    Join Date
    Feb 2007
    Posts
    327
    Plugin Contributions
    0

    Default Re: PHP Warning: Undefined array key "products_id"

    Quote Originally Posted by lat9 View Post
    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.


  4. #4
    Join Date
    Jan 2005
    Posts
    55
    Plugin Contributions
    0

    Default Re: PHP Warning: Undefined array key "products_id"

    Quote Originally Posted by lat9 View Post
    don't see where $_GET['products_id'] disappeared to ... since it's part of the URL included in that log.
    Code:
    $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()));
    }
    Code:
    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

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,973
    Plugin Contributions
    96

    Default Re: PHP Warning: Undefined array key "products_id"

    Quote Originally Posted by nl2dav View Post
    Code:
    $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()));
    }
    Code:
    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.

  6. #6
    Join Date
    Jan 2005
    Posts
    55
    Plugin Contributions
    0

    Default 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

    Code:
    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

    Code:
    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*

 

 

Similar Threads

  1. RE: PHP Warning: Undefined array key 0
    By dsc7050 in forum Upgrading to 2.x.x
    Replies: 3
    Last Post: 16 Apr 2024, 10:28 PM
  2. v158 Undefined array key "HTTP_USER_AGENT"
    By royaldave in forum Upgrading to 1.5.x
    Replies: 0
    Last Post: 1 Mar 2024, 01:26 AM
  3. Undefined array key "gender"
    By royaldave in forum Bug Reports
    Replies: 0
    Last Post: 19 Feb 2024, 10:11 AM
  4. UPS Shipping Undefined array key "methods"
    By bumba000 in forum General Questions
    Replies: 1
    Last Post: 26 May 2023, 07:19 PM

Posting Permissions

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