We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53766
    • 5 Posts
    I followed Bob's guide (https://bobsguides.com/custom-db-tables.html) for editing a row in a custom database table. However, I encountered a problem where my table row is not saving/updating and not given errors in my MODX error log.

    I call my snippet like so:
    [[!EditEISorders? &FullName=`[[GetFullname]]`]]


    My snippet looks like this (table full name is EIS_Orders where 'Order' is the Primary key):
    <?php
    /* EditQuote Snippet */
     
    /* Load our class */
    $path = MODX_CORE_PATH . 'components/EIS/';
    $result = $modx->addPackage('EIS',$path .
        'model/','EIS_');
    if (! $result) {
        return 'Failed to add package';
    }
     
    /* Get the existing Quote */
    $FullName = $scriptProperties['FullName'];
    $order = $modx->getObject('Orders',
        array('FullName'=>$FullName));
     
    /* Show error message if quote is not found */
    if (empty($order)) {
        return ('Could not find Order with Full Name: ' . $FullName . 'end');
    }
     
    if (isset($_POST['submit']) &&
        ($_POST['submit'] == 'submit')) {
     
        /* Form has been submitted */
     
        $order->set('Order', $_POST['Order']); /*Primary Key*/
        $order->set('FullName', $_POST['FullName']);
        $order->set('CustomerName', $_POST['CustomerName']);
        $order->set('InstallDate', $_POST['InstallDate']);
        $order->set('ZIP', $_POST['ZIP']);
        $order->set('PurchasePrice', $_POST['PurchasePrice']);
        $order->set('BasicInstallationFee', $_POST['BasicInstallationFee']);
        $order->set('DeliveryOption', $_POST['DeliveryOption']);
        $order->set('AdditionalMiles', $_POST['AdditionalMiles']);
        $order->set('AdditionalServices', $_POST['AdditionalServices']);
        $order->set('AdditionalPainting', $_POST['AdditionalPainting']);
        $order->set('ParkingToll', $_POST['ParkingToll']);
        $order->set('RRPee', $_POST['RRPee']);
        $order->set('OtherProducts', $_POST['OtherProducts']);
        $order->set('OtherTip', $_POST['OtherTip']);
        $order->set('Adjustment', $_POST['Adjustment']);
        $order->set('Reason', $_POST['Reason']);
        $order->set('Tax', $_POST['Tax']);
        $order->set('TotalInstallationCharge ', $_POST['TotalInstallationCharge']);
        
        if ( $order->save()) {
            $output = "Order Saved" . $order->get('Order');
        } else {
            $output = "Error";
        }
    } else {
        /* Not a repost, just display the form */
     
        /* The second argument to getChunk() tells MODX
         * to replace the placeholders with the existing
         * quote's values
         */
     
        $output = $modx->getChunk('EISaddOrder',$order->toArray() );
    }
    return $output;


    If I were to set the primary key 'Order' to Order 12341234 it would output "Order Saved12341234" however when I go into mySQL table or refresh the page, the changes do not persist.

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      If you put this on the page:

      [[+show_post]]


      And this in your snippet:

      $modx->setPlaceholder('show_post', print_r($_POST, true);


      do all the fields look good when you submit the form?

      BTW, since you're calling the GetFullName snippet cached (without the exclamation point), it may be returning an old value from the cache. Could you call it in your EditEISorders snippet with $modx->runSnippet().



        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
        • 53766
        • 5 Posts
        Thanks Bob for guide and your input to my problem. I manually displayed all my fields after it is saved and it looks all the fields look good when I submit the form. I also made my GetFullName snippet uncached and tried it's equivalent $modx->runSnippet(). I also recreated my package however none of this solved my problem. my $object->save() still doesn't work.
          • 53766
          • 5 Posts
          I've narrowed down the problem to I'm unable to alter the primary key. When I do, the whole snippet does not work.
          • discuss.answer
            • 3749
            • 24,544 Posts
            Yes, that's pretty much always the case. Altering a primary key value can have all kinds of bad side effects and there's almost never a good reason for doing it.
              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