We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6808
    • 7 Posts
    I follow the tutorial through several times. the DB table is created to the specs in the schema file but the collection count shows Total: 01, and the I can not add a record to the table. I used PHPMyAdmin to add a record set and still not getting a correct total for the Collection count.

    I looked at the files for several other Add Ons and all files created by the build script seem correct not sure where to look to next to troubleshoot.
      • 4172
      • 5,888 Posts
      which code did you try. Do you want to post it here?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 6808
        • 7 Posts
        Wow - quick response thank you.

        Here is the snippet code
        <?php
        $base_path = $modx->getOption('core_path').'/components/newsletter/';
        
        
        $o = '';
        $f = $base_path.'snippet.newsletter.php';
        if (file_exists($f)) {
           $o = include $f;
        } else {
           $modx->setLogTarget('ECHO');
           $modx->log(modX::LOG_LEVEL_ERROR,'CA Newsletter not found at: '.$f);
        }
        return $o;


        Here is the PHP code the snippet calls:

        <?php
        /**
         * @package newsletter
         */
        $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/newsletter/';
        
        $modx->addPackage('newsletter',$base_path.'model/');
        
        $email = $modx->newObject('nlEmail');
        $email->fromArray(array(
            'name' => 'Dave',
            'email' => '[email protected]',
        	'sent' => '0',
        	'unsubscribe' => '0',
        
        ));
        $email->save();
        
        $emails = $modx->getCollection('nlEmail');
        echo 'Total: '.count($emails);


        Here is an error in the log that may pertain to the problem:

        [2010-12-16 11:42:57] (ERROR @ /manager/index.php) Error preparing statement for query: SELECT `modActionDom`.`id` AS `modActionDom_id`, `modActionDom`.`action` AS `modActionDom_action`, `modActionDom`.`name` AS `modActionDom_name`, `modActionDom`.`description` AS `modActionDom_description`, `modActionDom`.`xtype` AS `modActionDom_xtype`, `modActionDom`.`container` AS `modActionDom_container`, `modActionDom`.`rule` AS `modActionDom_rule`, `modActionDom`.`value` AS `modActionDom_value`, `modActionDom`.`constraint` AS `modActionDom_constraint`, `modActionDom`.`constraint_field` AS `modActionDom_constraint_field`, `modActionDom`.`constraint_class` AS `modActionDom_constraint_class`, `modActionDom`.`active` AS `modActionDom_active`, `modActionDom`.`for_parent` AS `modActionDom_for_parent` FROM `modx_actiondom` AS `modActionDom` LEFT JOIN `modx_access_actiondom` `Access` ON `modActionDom`.`id` = `Access`.`target` WHERE ( `modActionDom`.`action` = ? AND `modActionDom`.`active` = ? AND `modActionDom`.`for_parent` = ? AND ( ( `Access`.`principal_class` = ? AND `Access`.`principal` IN (1) ) OR `Access`.`principal` IS ? ) ) - Array
        (
        [0] => 42000
        [1] => 1064
        [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’? ) )’ at line 1
          • 3749
          • 24,544 Posts
          I can see a few issues.

          Take the first slash out of the $base_path. All MODx paths end in a slash, so the core_path will have one at the end. As it is, you’ll have core//components.
          You can also use:

          $base_path = MODX_CORE_PATH . 'components/newsletter/';


          Also, change this:

          echo 'Total: '.count($emails);

          to
          return 'Total: '.count($emails);


          Finally, check the return from $modx->addPackage() to make sure the package was loaded successfully. It returns true on success and (I think) false on failure.

          If none of that helps, there may be a typo in your schema.

          You could try generating a new one from the table using the method here: http://bobsguides.com/custom-db-tables.html

          Hope this helps. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 6808
            • 7 Posts
            Absolutely perfect fix. Thanks BobRay.
              • 3749
              • 24,544 Posts
              Quote from: dbunten at Dec 16, 2010, 02:18 PM

              Absolutely perfect fix. Thanks BobRay.

              Glad it worked. Thanks for reporting back. smiley
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting