Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Fatal error in admin/includes/functions/general_functions.php

    Fatal error received attempting to edit banner in the admin. The error log is:

    [13-Jun-2022 14:54:23 America/New_York] Request URI: /admin/index.php?cmd=banner_manager&page=1&bID=14&action=new, IP address: xx.xxx.xxx.xxx
    --> PHP Fatal error: Uncaught TypeError: Unsupported operand types: string + int in /path to admin/includes/functions/general.php:2230
    Stack trace:
    #0 /path to admin/banner_manager.php(366): zen_set_field_length('banners', 'banners_sort_or...')
    #1 /path to admin/index.php(11): require('partial path to store')
    #2 {main}
    thrown in /path to admin/includes/functions/general.php on line 2230.
    The error occurs in function zen_set_field_length, code follows:
    Code:
    /**
     * return the size and maxlength settings in the form size="blah" maxlength="blah" based on maximum size being 50
     * uses $tbl = table name, $fld = field name
     * example: zen_set_field_length(TABLE_CATEGORIES_DESCRIPTION, 'categories_name')
     * @param string $tbl
     * @param string $fld
     * @param int $max
     * @param bool $override
     * @return string
     */
    function zen_set_field_length($tbl, $fld, $max = 50, $override = false)
    {
        $field_length = zen_field_length($tbl, $fld);
        switch (true) {
            case (($override == false and $field_length > $max)):
                $length = 'size="' . ($max + 1) . '" maxlength="' . $field_length . '"';
                break;
            default:
                $length = 'size="' . ($field_length + 1) . '" maxlength="' . $field_length . '"';
                break;
        }
        return $length;
    }
    Line 2230 is the line in red. I have traced the problem to a call to the function with $tbl = TABLE_BANNERS, and $fld = 'banners_sort_order'. Function zen_field_length returns an empty variable for $field_length, I assume an empty string.

    I suspect the issue may be due to the version of mysql. The error occurs on mysql 8.0.28 but not on mysql 5.7.34. mysql 8.0.28 has eliminated the length attribute for integers, which apparently was associated with the display length, not the size of the stored integer, but I'm not certain of the impact of the change when it comes to zen_field_length. I suspect the error may also occur for other admin functions but I don't have any hard data, just a nagging memory of other errors in admin.

    Suggestions for a temporary or permanent fix would be appreciated.

    zc157c, php8.0.2, mysql 8.0.28

    Dave

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,681
    Plugin Contributions
    123

    Default Re: Fatal error in admin/includes/functions/general_functions.php

    Edit includes/classes/db/mysql/query_factory.php
    after line 717
    $this->max_length = preg_replace('/[a-z\(\)]/', '', $type);
    add:

    Code:
            if (empty($this->max_length)) {
                if (strtoupper($type) === 'DATE') $this->max_length = 10;
                if (strtoupper($type) === 'DATETIME') $this->max_length = 19; // ignores fractional which would be 26
                if (strtoupper($type) === 'TIMESTAMP') $this->max_length = 19; // ignores fractional which would be 26
                if (strtoupper($type) === 'TINYTEXT') $this->max_length = 255; 
                if (strtoupper($type) === 'INT') $this->max_length = 11; 
                if (strtoupper($type) === 'TINYINT') $this->max_length = 4; 
                if (strtoupper($type) === 'SMALLINT') $this->max_length = 4; 
            }
    Last edited by swguy; 14 Jun 2022 at 12:00 PM.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  3. #3
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,681
    Plugin Contributions
    123

    Default Re: Fatal error in admin/includes/functions/general_functions.php

    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,681
    Plugin Contributions
    123

    Default Re: Fatal error in admin/includes/functions/general_functions.php

    Dave, for documentation please run SHOW COLUMNS FROM banners; and post the results so people can see the 8.0.17+ difference.
    Here it is in MySQL 5.7:


    Code:
    mysql> SHOW COLUMNS FROM banners;
    +--------------------------+--------------+------+-----+---------------------+----------------+
    | Field                    | Type         | Null | Key | Default             | Extra                            |
    +--------------------------+--------------+------+-----+---------------------+----------------+
    | banners_id           | int(11)      | NO   | PRI | NULL                | auto_increment            |
    ...
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  5. #5
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Fatal error in admin/includes/functions/general_functions.php

    Here's the SHOW COLUMNS FROM banners results for the zen cart 8.0.28 database:
    Code:
    SHOW COLUMNS FROM banners;
    
    banners_id	int	NO	PRI	NULL	auto_increment	
    banners_title	varchar(64)	NO				
    banners_url	varchar(255)	NO				
    banners_image	varchar(255)	NO				
    banners_group	varchar(15)	NO				
    banners_html_text	mediumtext	YES		NULL		
    expires_impressions	int	YES		0		
    expires_date	datetime	YES	MUL	NULL		
    date_scheduled	datetime	YES	MUL	NULL		
    date_added	datetime	NO		0001-01-01 00:00:00		
    date_status_change	datetime	YES		NULL		
    status	int	NO	MUL	1		
    banners_open_new_windows	int	NO		1		
    banners_on_ssl	int	NO		1		
    banners_sort_order	int	NO		0
    and from the 5.7.34 database:
    Code:
    SHOW COLUMNS FROM banners;
    
    banners_id	int(11)	NO	PRI	NULL   auto_increment	
    banners_title	varchar(64)	NO				
    banners_url	varchar(255)	NO				
    banners_image	varchar(255)	NO				
    banners_group	varchar(15)	NO				
    banners_html_text	mediumtext	YES		NULL
    expires_impressions	int(7)	YES		0		
    expires_date	datetime	YES	MUL	NULL
    date_scheduled	datetime	YES	MUL	NULL
    date_added	datetime	NO		0001-01-01 00:00:00		
    date_status_change	datetime	YES		NULL
    status	int(1)	NO	MUL	1		
    banners_open_new_windows	int(1)	NO		1		
    banners_on_ssl	int(1)	NO		1		
    banners_sort_order	int(11)	NO		0
    Thank you for the rapid response!
    Dave

  6. #6
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Fatal error in admin/includes/functions/general_functions.php

    The fix appears to work, at least no fatal errors editing banners.
    Thanks again,
    Dave

  7. #7
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Fatal error in admin/includes/functions/general_functions.php

    The title of this thread is incorrect. It should be "Fatal error in admin/includes/functions/general.php". I hope that mistake did not create any confusion on which file was involved.
    Dave

  8. #8
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,681
    Plugin Contributions
    123

    Default Re: Fatal error in admin/includes/functions/general_functions.php

    No worries, thanks for testing. This will be fixed in 1.5.8.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

 

 

Similar Threads

  1. v156 /includes/functions /admin/includes/functions Why do the same functions exist?
    By shrimp-gumbo-mmmhhh in forum General Questions
    Replies: 2
    Last Post: 8 May 2019, 08:00 AM
  2. v151 admin/includes/functions/compatibility.php
    By makenoiz in forum Upgrading to 1.5.x
    Replies: 6
    Last Post: 11 Dec 2012, 11:53 PM
  3. Replies: 2
    Last Post: 28 Jan 2009, 05:45 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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR