Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18
  1. #11
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to display select information from database

    All files that have a suffix (end with) of '.php' and do not begin with an underscore that are within that folder are loaded by the system on each page load. So the define provided above will be loaded providing a sort of fill-in-the-blank result for php.

    After that define is processed, anywhere in php code (after the opening tag of <?php and if present before the closing tag of ?>) anywhere that TABLE_GIFTCARDS is used (without quotes) it would be as if the entry is DB_PREFIX . 'giftcards' and note that DB_PREFIX is defined earlier in includes/configure.php so it's value is substituted in there as well such that in the case described above DB_PREFIX is 'zen_' making TABLE_GIFTCARDS to be 'zen_giftcards'.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  2. #12
    Join Date
    Apr 2012
    Location
    Los Angeles, CA
    Posts
    185
    Plugin Contributions
    2

    Default Re: How to display select information from database

    Quote Originally Posted by mc12345678 View Post
    All files that have a suffix (end with) of '.php' and do not begin with an underscore that are within that folder are loaded by the system on each page load. So the define provided above will be loaded providing a sort of fill-in-the-blank result for php.

    After that define is processed, anywhere in php code (after the opening tag of <?php and if present before the closing tag of ?>) anywhere that TABLE_GIFTCARDS is used (without quotes) it would be as if the entry is DB_PREFIX . 'giftcards' and note that DB_PREFIX is defined earlier in includes/configure.php so it's value is substituted in there as well such that in the case described above DB_PREFIX is 'zen_' making TABLE_GIFTCARDS to be 'zen_giftcards'.
    Ok, so now I have the Define in place and I am getting this error now:

    Code:
    [09-Jul-2019 23:16:45 America/Los_Angeles] PHP Fatal error:  Call to a member function RecordCount() on null in /home/sammirah/public_html/webstore/includes/modules/pages/giftcards_lookup/header_php.php on line 19
    When I got to that file line 19 reads:
    Code:
    <?php
    /**
     * giftcard lookup info
     *
     * @package page
     * @copyright Copyright 2003-2019 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version GIT: $Id: Author: Sammirah.  Friday, April 12, 2019 18:36 PM Modified in v1.5.5f $
     */
    
      require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
      $text_giftcards_help = '';
      if (isset($_POST['lookup_giftcards_lookup']) and $_POST['lookup_giftcards_lookup'] != '') {
    // lookup requested giftcard
    
        $giftcard = $db->Execute("select * from " . TABLE_GIFTCARDS . " where giftcard_code = '" . zen_db_input($_POST['lookup_giftcards_lookup']) . "' and  giftcard_active != 'Y'");
        $_POST['lookup_giftcards_lookup'] = zen_sanitize_string($_POST['lookup_giftcards_lookup']);
        if ($giftcards->RecordCount(1) < 1) {
    // invalid giftcard code
          $text_giftcards_help = sprintf(TEXT_GIFTCARD_FAILED, zen_output_string_protected($_POST['lookup_giftcards_lookup']));
        } else {
    // valid giftcard code
          $lookup_giftcard_id = $giftcards->fields['giftcard_id'];
    
          $giftcard_value = $giftcards->fields['giftcard_value'];
          switch ($giftcards->fields['giftcard_active']) {
            case 'Y':
            $text_giftcards_help .= sprintf(TEXT_GIFTCARDS_HELP_FIXED, $currencies->format($giftcards->fields['giftcard_balance']));
            break;
            case 'P':
            $text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, number_format($coupon->fields['coupon_amount'],2). '%');
            break;
            default:
          }
         
          $text_giftcard_help .= sprintf(TEXT_GIFTCARD_HELP_DATE, zen_date_short($giftcard->fields['date_modified']));
        }
      }
    
    // include template specific file name defines
    $define_page = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/', FILENAME_DEFINE_GIFTCARDS_LOOKUP, 'false');
    $breadcrumb->add(NAVBAR_TITLE);
    ?>
    As I am modeling this after DISCOUNT_COUPON, I am afraid I have completely missed a step. Perhaps someone else can see something I can't.

  3. #13
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to display select information from database

    To be able to identify why $db is not defined in this particular usage, would need to understand the stack history of when the error is caused. This is usually identifiable by the remainder of the mydebug log that was not shown.

    The discount_coupon header_php.php file also has a similar format so in calling the above header file something is missing. The normal usage of that file is for it to be in the global space which is where $db is defined. If it is called within a function, the $db must be made global as well as any other global variable needed.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #14
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default Re: How to display select information from database

    Looking at the code you posted, it's a different variable that receives the result of the $db->Execute call than that used to determine the call's results:
    Code:
        $giftcard = $db->Execute("select * from " . TABLE_GIFTCARDS . " where giftcard_code = '" . zen_db_input($_POST['lookup_giftcards_lookup']) . "' and  giftcard_active != 'Y'");
        $_POST['lookup_giftcards_lookup'] = zen_sanitize_string($_POST['lookup_giftcards_lookup']);
        if ($giftcards->RecordCount(1) < 1) {
    It looks like you should change the variable that receives the result to $giftcards.

  5. #15
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to display select information from database

    Quote Originally Posted by lat9 View Post
    Looking at the code you posted, it's a different variable that receives the result of the $db->Execute call than that used to determine the call's results:
    Code:
        $giftcard = $db->Execute("select * from " . TABLE_GIFTCARDS . " where giftcard_code = '" . zen_db_input($_POST['lookup_giftcards_lookup']) . "' and  giftcard_active != 'Y'");
        $_POST['lookup_giftcards_lookup'] = zen_sanitize_string($_POST['lookup_giftcards_lookup']);
        if ($giftcards->RecordCount(1) < 1) {
    It looks like you should change the variable that receives the result to $giftcards.
    Yeah, sorry, for some reason I was latched on the database access part of the issue not that attempting to access the records that were returned. Definitely agree that the use of $giftcards instead of $giftcard there and possibly other "duplicated" code is the cause of that error. After resolution of that one issue, would suggest reviewing the other instances of $giftcard to validate that it is always either just $giftcard or $giftcards.

    Can use the developers tool kit to search for $giftcard and see where that is used and if it applies to this revision and if so whether it should be singular or plural.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #16
    Join Date
    Apr 2012
    Location
    Los Angeles, CA
    Posts
    185
    Plugin Contributions
    2

    Default Re: How to display select information from database

    Quote Originally Posted by lat9 View Post
    Looking at the code you posted, it's a different variable that receives the result of the $db->Execute call than that used to determine the call's results:
    Code:
        $giftcard = $db->Execute("select * from " . TABLE_GIFTCARDS . " where giftcard_code = '" . zen_db_input($_POST['lookup_giftcards_lookup']) . "' and  giftcard_active != 'Y'");
        $_POST['lookup_giftcards_lookup'] = zen_sanitize_string($_POST['lookup_giftcards_lookup']);
        if ($giftcards->RecordCount(1) < 1) {
    It looks like you should change the variable that receives the result to $giftcards.
    Thanks, I totally did not notice that. I removed the (s) and it got the page to at least give a response as shown here:
    Name:  gclookup.PNG
Views: 51
Size:  5.7 KB

    But being that I know the gift card code is active, I think the problem lies in things I removed or change in the original DISCOUNT_COUPON code. Which was a great deal as the bulk of it dealt with a field called coupon_type which is not present in the giftcards database but is ultimately linked to information I need. Below is the original code, the sections in the red was the only portion I understood and the rest computes in my brain as a complete "cluster-bleep" so I took it out. Now that I am looking with fresh eyes, I see sever DB calls that I am sure I should include. Not even sure the languages_id or text_coupon_help is about or if I need it at all.

    Code:
    // valid discount coupon code
          $lookup_coupon_id = $coupon->fields['coupon_id'];
    
          $coupon_desc = $db->Execute("select * from " . TABLE_COUPONS_DESCRIPTION . " where coupon_id = '" . (int)$lookup_coupon_id . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'");
          $text_coupon_help = TEXT_COUPON_HELP_HEADER;
          $text_coupon_help .= sprintf(TEXT_COUPON_HELP_NAME, $coupon_desc->fields['coupon_name']);
          if (zen_not_null($coupon_desc->fields['coupon_description'])) $text_coupon_help .= sprintf(TEXT_COUPON_HELP_DESC, $coupon_desc->fields['coupon_description']);
          $coupon_amount = $coupon->fields['coupon_amount'];
          switch ($coupon->fields['coupon_type']) {
            case 'F':
            $text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, $currencies->format($coupon->fields['coupon_amount']));
            break;
            case 'P':
            $text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, number_format($coupon->fields['coupon_amount'],2). '%');
            break;
            case 'S':
            $text_coupon_help .= TEXT_COUPON_HELP_FREESHIP;
            break;
            default:
          }
          if ($coupon->fields['coupon_minimum_order'] > 0 ) $text_coupon_help .= sprintf(TEXT_COUPON_HELP_MINORDER, $currencies->format($coupon->fields['coupon_minimum_order']));
          $text_coupon_help .= sprintf(TEXT_COUPON_HELP_DATE, zen_date_short($coupon->fields['coupon_start_date']),zen_date_short($coupon->fields['coupon_expire_date']));
          $text_coupon_help .= TEXT_COUPON_HELP_RESTRICT;
    
          if ($coupon->fields['coupon_zone_restriction'] > 0) {
            $text_coupon_help .= TEXT_COUPON_GV_RESTRICTION_ZONES;
          }
    
          $text_coupon_help .= TEXT_COUPON_HELP_CATEGORIES;
          $get_result=$db->Execute("select * from " . TABLE_COUPON_RESTRICT . "  where coupon_id='" . (int)$lookup_coupon_id . "' and category_id !='0'");
          $cats = array();
          if ($get_result->RecordCount() == 1 && $get_result->fields['category_id'] == '-1') {
            $cats[] = array("link" => TEXT_NO_CAT_TOP_ONLY_DENY);
          } else {
            $skip_cat_restriction = true;
            while (!$get_result->EOF) {
              if ($get_result->fields['coupon_restrict'] == 'N') {
                $restrict = TEXT_CAT_ALLOWED;
              } else {
                $restrict = TEXT_CAT_DENIED;
              }
              if ($get_result->RecordCount() >= 1 and $get_result->fields['category_id'] != '-1') {
                $result = $db->Execute("SELECT * FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd WHERE c.categories_id = cd.categories_id
                and cd.language_id = '" . (int)$_SESSION['languages_id'] . "' and c.categories_id='" . $get_result->fields['category_id'] . "'");
                $cats[] = array("validity"=> ($get_result->fields['coupon_restrict'] =='N' ? 'A' : 'D'), 'name'=> $result->fields["categories_name"], 'link'=>'<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$result->fields['categories_id']) . '">' . $result->fields["categories_name"] . '</a>' . $restrict);
              }
              $get_result->MoveNext();
            }
      //echo 'CAT SIZE: ' . sizeof($cats) . ' - ' . ' $restrict: ' . $restrict . '<br>';
    
            if ($skip_cat_restriction == false || sizeof($cats) == 0) $cats[] = array("link" => TEXT_NO_CAT_RESTRICTIONS);
          }
          sort($cats);
          $mycats = array();
          foreach($cats as $key=>$value) {
            $mycats[] = $value["link"];
          }
          $cats = '<ul id="couponCatRestrictions">' . '<li>' . implode('<li>', $mycats) . '</ul>';
          $text_coupon_help .= $cats;
    
          $text_coupon_help .= TEXT_COUPON_HELP_PRODUCTS;
          $get_result=$db->Execute("select * from " . TABLE_COUPON_RESTRICT . "  where coupon_id='" . (int)$lookup_coupon_id . "' and product_id !='0'");
          $prods = array();
          while (!$get_result->EOF) {
            if ($get_result->fields['coupon_restrict'] == 'N') {
              $restrict = TEXT_PROD_ALLOWED;
            } else {
              $restrict = TEXT_PROD_DENIED;
            }
            $result = $db->Execute("SELECT * FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd WHERE p.products_id = pd.products_id and
            pd.language_id = '" . (int)$_SESSION['languages_id'] . "' and p.products_id = '" . $get_result->fields['product_id'] . "'");
            $prods[] = array("validity" => ($get_result->fields['coupon_restrict'] =='N' ? 'A' : 'D'), 'name'=> $result->fields["products_name"], 'link'=> '<a href="' . zen_href_link(zen_get_info_page($result->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($result->fields['master_categories_id']) . '&products_id=' . $result->fields['products_id']) . '">' . $result->fields['products_name'] . '</a>' . $restrict);
            $get_result->MoveNext();
          }
    
          if (sizeof($prods) == 0) $prods[] = array("link"=>TEXT_NO_PROD_RESTRICTIONS);
    
          sort($prods);
          $myprods = array();
          foreach($prods as $key=>$value) {
            $myprods[] = $value["link"];
          }
          $prods = '<ul id="couponProdRestrictions">' . '<li>' . implode('<li>', $myprods) . '</ul>';
          $text_coupon_help .= $prods . TEXT_COUPON_GV_RESTRICTION;
        }
      }
    What I want is to allow customers to put in their gift card code and get back two values from the giftcards database: giftcard_value and giftcard_balance. Being that all of my gift card codes are randomly generated it should not have any keygen testing security issues, but will allow customers to get the primary info they need to know without having to wait 24 hours for me to email or text the info.

    I just need help understanding what part of the code I need to alter and what part I can discard.
    Last edited by sammirah; 11 Jul 2019 at 05:18 PM. Reason: typos

  7. #17
    Join Date
    Apr 2012
    Location
    Los Angeles, CA
    Posts
    185
    Plugin Contributions
    2

    Default Re: How to display select information from database

    If there is not a database for descriptions or if a particular field does not exist can the line be excluded from header.php? For instance the code below doesn't necessarily apply to gift cards as it does in discount coupon. Is it safe to remove it or should I change it to reflect the giftcard database just in case it effects the remaining sections?

    Code:
      $text_giftcards_help .= sprintf(TEXT_GIFTCARDS_HELP_NAME, $giftcards_desc->fields['giftcard_name']);
          if (zen_not_null($giftcards_desc->fields['coupon_description'])) $text_coupon_help .= sprintf(TEXT_GIFTCARDS_HELP_DESC, $coupon_desc->fields['coupon_description']);
          $coupon_amount = $coupon->fields['coupon_amount'];
          switch ($coupon->fields['coupon_type']) {
            case 'F':
            $text_coupon_help .= sprintf(TEXT_GIFTCARDS_HELP_FIXED, $currencies->format($coupon->fields['coupon_amount']));
            break;
            case 'P':
            $text_coupon_help .= sprintf(TEXT_GIFTCARDS_HELP_FIXED, number_format($coupon->fields['coupon_amount'],2). '%');
            break;
            case 'S':
            $text_coupon_help .= TEXT_GIFTCARDS_HELP_FREESHIP;
            break;
            default:
          }

  8. #18
    Join Date
    Apr 2012
    Location
    Los Angeles, CA
    Posts
    185
    Plugin Contributions
    2

    Default Re: How to display select information from database

    Quote Originally Posted by sammirah View Post
    If there is not a database for descriptions or if a particular field does not exist can the line be excluded from header.php? For instance the code below doesn't necessarily apply to gift cards as it does in discount coupon. Is it safe to remove it or should I change it to reflect the giftcard database just in case it effects the remaining sections?

    Code:
      $text_giftcards_help .= sprintf(TEXT_GIFTCARDS_HELP_NAME, $giftcards_desc->fields['giftcard_name']);
          if (zen_not_null($giftcards_desc->fields['coupon_description'])) $text_coupon_help .= sprintf(TEXT_GIFTCARDS_HELP_DESC, $coupon_desc->fields['coupon_description']);
          $coupon_amount = $coupon->fields['coupon_amount'];
          switch ($coupon->fields['coupon_type']) {
            case 'F':
            $text_coupon_help .= sprintf(TEXT_GIFTCARDS_HELP_FIXED, $currencies->format($coupon->fields['coupon_amount']));
            break;
            case 'P':
            $text_coupon_help .= sprintf(TEXT_GIFTCARDS_HELP_FIXED, number_format($coupon->fields['coupon_amount'],2). '%');
            break;
            case 'S':
            $text_coupon_help .= TEXT_GIFTCARDS_HELP_FREESHIP;
            break;
            default:
          }
    So I found this code from ot_giftcard.php that provides information that I need in my Gift Card Lookup:
    Code:
             //get the activation status from the db
             $giftcard_result = $db->Execute("select giftcard_active from " . TABLE_GIFTCARDS . " where giftcard_code = '" . strval($giftcard_code) . "'");
             if ($giftcard_result->RecordCount() > 0)
             {
                if ($giftcard_result->fields['giftcard_active'] == 'Y')
                {
                   //the card is activated
                   return true;
                }
                else
                {
                  //the card is not activated
                  return false;
                }
    Is it possible to use the above code somewhere in the following to get the information I need to display? I am thinking I can use it in the highlighted areas of the following files.

    Code:
     require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
      $text_giftcards_help = '';
      if (isset($_POST['lookup_giftcards_lookup']) and $_POST['lookup_giftcards_lookup'] != '') {
    // lookup requested giftcard
    
        $giftcards = $db->Execute("select * from " . TABLE_GIFTCARDS . " where giftcard_code = '" . zen_db_input($_POST['lookup_giftcards_lookup']) . "' and  giftcard_active != 'Y' ");
        $_POST['lookup_giftcards_lookup'] = zen_sanitize_string($_POST['lookup_giftcards_lookup']);
        if ($giftcards->RecordCount() < 1) {
    // invalid giftcard code
          $text_giftcards_help = sprintf(TEXT_GIFTCARDS_FAILED, zen_output_string_protected($_POST['lookup_giftcards_lookup']));
        } else {
    // valid giftcard code
          $lookup_giftcards_id = $giftcards->fields['giftcard_id'];
    
          $giftcards = $db->Execute("select * from " . TABLE_GIFTCARDS . " where giftcard_id = '" . (int)$lookup_giftcards_id . "' and language_id = '" . (int)$_SESSION['languages_id'] . "'");
          $text_giftcards_help = TEXT_GIFTCARDS_HELP_HEADER;
          $text_giftcards_help .= sprintf(TEXT_GIFTCARDS_VALUE, $giftcards->fields['giftcard_value']);
          $text_giftcards_help .= sprintf(TEXT_GIFTCARDS_BALANCE, $giftcards->format($giftcards->fields['giftcard_balance']));
          $text_giftcards_help .= sprintf(TEXT_GIFTCARDS_HELP_DATE, zen_date_short($giftcards->fields['date_created']),zen_date_short($giftcards->fields['date_modified']));
          }
      }
    
    // include template specific file name defines
    $define_page = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/', FILENAME_DEFINE_GIFTCARDS_LOOKUP, 'false');
    $breadcrumb->add(NAVBAR_TITLE);
    ?>
    or

    Code:
    ?>
    <div class="centerColumn" id="giftcardslookupInfo">
    <h1 id="giftcardslookupInfoHeading"><?php echo HEADING_TITLE; ?></h1>
    
    <div id="giftcardslookupInfoMainContent" class="content">
    <?php if ((DEFINE_GIFTCARD_ACTIVE >= 1 and DEFINE_GIFTCARDS_LOOKUP_STATUS <= 2) && $text_giftcards_help == '') {
      require($define_page);
     } else {
      echo $text_giftcards_help;
    } ?>
    </div>
    
    <?php echo zen_draw_form('giftcards_lookup', zen_href_link(FILENAME_GIFTCARDS_LOOKUP, 'action=lookup', 'SSL', false)); ?>
    <fieldset>
    <legend><?php echo TEXT_GIFTCARDS_LOOKUP_ID_INFO; ?></legend>
    <label class="inputLabel" for="lookup-giftcards-lookup"><?php echo TEXT_GIFTCARDS_LOOKUP_ID; ?></label>
    <?php echo zen_draw_input_field('lookup_giftcards_lookup', $_POST['lookup_giftcards_lookup'], 'size="40" id="lookup-giftcards-lookup"');?>
    </fieldset>
    
    <?php if ($text_giftcards_help == '') { ?>
    <div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_SEND, BUTTON_LOOKUP_ALT); ?></div>
    <?php } else { ?>
    <div class="buttonRow forward"><?php echo '<a href="' . zen_href_link(FILENAME_GIFTCARDS_LOOKUP) . '">' . zen_image_button(BUTTON_IMAGE_CANCEL, BUTTON_CANCEL_ALT) . '</a>&nbsp;&nbsp;' . zen_image_submit(BUTTON_IMAGE_SEND, BUTTON_LOOKUP_ALT); ?></div>
    <?php } ?>
    <div class="buttonRow back"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT) . '</a>'; ?></div>
    <br class="clearBoth" />
    </form>
    </div>
    Last edited by sammirah; 13 Jul 2019 at 10:52 AM.

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. v153 How do I Display Additional Read Only Product Information from Custom Product Fields
    By FoodSourceDirect in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 5 Aug 2014, 08:42 PM
  2. Replies: 8
    Last Post: 24 Nov 2012, 02:12 PM
  3. how to move link from more information to information side box?
    By mrobson86 in forum General Questions
    Replies: 1
    Last Post: 21 Sep 2011, 09:01 PM
  4. How do I select tabular display ?
    By ruthnis in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 26 Jun 2007, 04:17 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