Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Jun 2016
    Location
    Minneapolis, MN
    Posts
    37
    Plugin Contributions
    0

    help question db Execute issue -- Undefined variable: $db

    Server OS: Linux 3.16.0-5-amd64
    Database: MySQL 5.6.39-1~dotdeb+7.1
    HTTP Server: Apache/2.4.10 (Debian) mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_fcgid/2.3.9 PHP/5.6.33-0+deb8u1 mod_python/3.3.1 Python/2.7.9 OpenSSL/1.0.1t
    PHP Version: 5.6.33-0+deb8u1 (Zend: 2.6.0)

    So I'm updating some custom code. This code is supposed to read values off a "master" database and then update it's own database with it. That part works fine. When I add a new product into my "master" zen-cart it is supposed to populate the "clone" sites but it never applies the markup. I need to change the code to start applying a markup/rounding to the prices in order to keep everything current.

    But after adding the new code I'm throwing this error:
    ] mod_fcgid: stderr: PHP Notice: Undefined variable: db in admin clone site/index.php on line 21, referer: admin clone site/login.php

    ] mod_fcgid: stderr: PHP Fatal error: Call to a member function Execute() on null in admin clone site/index.php on line 21, referer: admin clone site/login.php

    (i've cleaned them up)

    And it's only throwing this error on the site that has the new code.

    PHP Code:
    $sql_date $db->Execute("SELECT products_last_modified FROM " TABLE_PRODUCTS " WHERE 1 ORDER BY RAND() LIMIT 1;");
        
            
    $date strtotime($sql_date->fields['products_last_modified']);

        if((
    $date 43200) < time())

        {
            
    $update_sql "INSERT INTO products SELECT * FROM foreverpets.products

                                ON DUPLICATE KEY UPDATE 

                                products_price_w=VALUES(products_price),
                                                            
                                products_status=VALUES(products_status),
                                
                                                    
                                products_last_modified = NOW();"
    ;

            
    $db->Execute($update_sql);
            
            
    /* MAB add update price with markup */
        
            
    $markup $db->Execute("SELECT configuration_value FROM configuration WHERE configuration_key = STORE_MARKUP;");
            
            
    $rounding $db->Execute("SELECT configuration_value FROM configuration WHERE configuration_key = STORE_ROUNDING;");
            
            switch (
    $rounding
        {
            case 
    1//no rounding
                
    $prices_sql "UPDATE products 
                SET products_price=TRUNCATE((products_price_w * " 
    . ($markup 1) . "), 2);";
                break;
            case 
    2//nearest $0.99
                
    $prices_sql "UPDATE products 
                SET products_price=((TRUNCATE((products_price_w * " 
    . ($markup 1) . "), 0)) - 0.01)+1;";
                break;
            case 
    3//nearest $1.00
                
    $prices_sql "UPDATE products 
                SET products_price=TRUNCATE((products_price_w * " 
    . ($markup 1) . "), 0)+1;";
                break;
        }
        
        
    $db->Execute($prices_sql);
            
            
        
        } 
    New code is after/*MAB

    This manifests as a HTTP error 500.

    Any help would be greatly appreciated, I now this isn't a Zen Cart issue.

  2. #2
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,823
    Plugin Contributions
    9

    Default Re: db Execute issue

    what is line 21? that is where your error is....

    i see a couple of potential problems. since the error is reporting on the execute and not knowing the line number, are you sure the constants:

    STORE_MARKUP
    STORE_ROUNDING

    are defined?

    you will definitely run into problems with the following variables:

    $markup
    $rounding

    as they are now db objects and you are treating them as variables. i think you want to use:

    $markup->fields['configuration_value']

    hope that gives you enough to go on.

    best.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  3. #3
    Join Date
    Jun 2016
    Location
    Minneapolis, MN
    Posts
    37
    Plugin Contributions
    0

    Default Re: db Execute issue

    Sorry about that but line 21 is the first line of code ($sql_date).

    I have fields in the configuration table name 'STORE_MARKUP' and 'STORE_ROUNDING'.

    should I replace $rounding with STORE_ROUNDING and $markup with 'STORE_MARKUP'?

    I am not quite sure of this syntax :
    $markup->fields['configuration_value']
    but what about the built in function: zen_get_configuration_key_value($lookup)

    so it would be

    prices_sql = "UPDATE products SET products_price=TRUNCATE((products_price_w * " . (". zen_get_configuration_key_value('STORE_MARKUP') . " + 1) . "), 2);";

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,255
    Plugin Contributions
    124

    Default Re: db Execute issue

    You want:

    Code:
            $markup = STORE_MARKUP; 
    
            $rounding = STORE_ROUNDING;
    assuming that STORE_MARKUP is a decimal value like 0.25.

    If it's "25" instead, you'll have to do math:

    Code:
            $markup = STORE_MARKUP / 100
    Last edited by swguy; 18 Apr 2018 at 08:36 PM.
    That Software Guy. My Store: Zen Cart Support
    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
    Nov 2005
    Location
    los angeles
    Posts
    2,823
    Plugin Contributions
    9

    Default Re: db Execute issue

    Quote Originally Posted by tmpinsnty View Post
    ] mod_fcgid: stderr: PHP Notice: Undefined variable: db in admin clone site/index.php on line 21, referer: admin clone site/login.php

    ] mod_fcgid: stderr: PHP Fatal error: Call to a member function Execute() on null in admin clone site/index.php on line 21, referer: admin clone site/login.php
    does this script have:

    require('includes/application_top.php');

    somewhere above this line?

    $db is undefined -> means application_top.php has not been included.

    as far as the constants, i believe what @swguy says will work (he's missing an equals sign). but again that is currently NOT the error being reported. it's failing before it gets there.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  6. #6
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,255
    Plugin Contributions
    124

    Default Re: db Execute issue

    $db being undefined could also be caused by being in a function and neglecting to global the variable.

    Code:
    global $db;
    Last edited by swguy; 19 Apr 2018 at 12:54 AM.
    That Software Guy. My Store: Zen Cart Support
    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.

  7. #7
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,823
    Plugin Contributions
    9

    Default Re: db Execute issue

    all the more reason for the OP to post the contents of the script from the beginning....

    best.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  8. #8
    Join Date
    Jun 2016
    Location
    Minneapolis, MN
    Posts
    37
    Plugin Contributions
    0

    Default Re: db Execute issue

    Quote Originally Posted by carlwhat View Post
    all the more reason for the OP to post the contents of the script from the beginning....

    best.
    Actually this is the beginning of the page. This code is on the admin/index.php page and is the first thing after the comment section. This code has been on there for a long time (like 3 years). I just added the code after it recently. It didn't need
    require('includes/application_top.php');
    before. I don't mind adding it now if it will solve the problem.

    @swguy: It is in the database as a float. I also have some code in global_price_manager the guy before me updated. There I store it in the database as a decimal.
    Last edited by tmpinsnty; 19 Apr 2018 at 02:00 PM. Reason: added some stuff

  9. #9
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,255
    Plugin Contributions
    124

    Default Re: db Execute issue

    In (an unmodified version of) admin/index.php, application_top.php is pulled in on the second line of code. Just put your code after this ... or better, after the header is included.
    That Software Guy. My Store: Zen Cart Support
    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.

  10. #10
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,823
    Plugin Contributions
    9

    Default Re: db Execute issue

    @tmpinsnty you need to understand a bit about ZC's architecture. if your code is placed before the include/application_top.php, that code will execute prior to initializing ZC.

    considering this in on the admin, your code will execute before the admin has even logged in.

    the fact that the code was there for 3 years w/o problems, only means you were not doing anything that caused problems in the code.

    there are few if any circumstances that i can see where custom code part of a ZC install needs to run PRIOR to the include of application_top.php.

    best.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v154 Tax Variable Undefined In GV Module
    By PaulRRogers in forum Bug Reports
    Replies: 0
    Last Post: 4 Mar 2015, 10:16 PM
  2. v150 $db-Execute() issue with fields... Please please please help.
    By Ooba_Scott in forum General Questions
    Replies: 11
    Last Post: 3 Oct 2012, 09:36 AM
  3. Possible IE9/session variable issue?
    By pfabrick in forum General Questions
    Replies: 1
    Last Post: 11 May 2011, 10:00 PM
  4. Undefined Notice: Use of undefined constant
    By TheOracle in forum Bug Reports
    Replies: 0
    Last Post: 6 May 2007, 06:33 PM

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