We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38970
    • 59 Posts
    Hey Guys,

    I am trying to update a 3rd party table here is the code I am using
    <?php
    if(isset($_POST) AND isset($_POST['site_id_val'])){
    
    if(isset($_POST['module_order']) and !empty($_POST['module_order'])){
        parse_str($_POST['module_order'], $_POST['module_order']);
        $_POST['module_order'] =$_POST['module_order']['modules'];
    }
    //update the module settings
    $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/ModuleOptions/';
    $modx->addPackage('ModuleOptions',$base_path.'model/');
    //foreach($_POST['SiteMods'] As $name =>$s){
        
        $stack = $modx->getCollection('SitesOptions', array(
                                                            'sites_id' => $_POST['site_id_val']
                                                            ));
        if(!$stack){
            var_dump($stack);
            DIE();
            return;
        }
        foreach($stack as $object) {
            echo "
    Current: Saved ".$object->get('sites_option')." VAL: ".$object->get('sites_value');
            if(!isset($_POST['SiteMods'][$object->get('sites_option')]) OR empty($_POST['SiteMods'][$object->get('sites_option')]))
                continue;
            $object->set('sites_value', $_POST['SiteMods'][$object->get('sites_option')]);
            $object->set('sites_option', $object->get('sites_option'));
            if($object->save()){
                echo "
    Success: Saved ".$object->get('sites_option')." TO: ".$_POST['SiteMods'][$object->get('sites_option')];
            }
            
        }
    }
    
    


    The output of those echo's is :
    Current: Saved country VAL: US||CA||DE
    Success: Saved country TO: US||CA||GB
    Current: Saved run VAL: no
    Success: Saved run TO: no
    Current: Saved check VAL: yes
    Success: Saved check TO: yes 
    


    As far as I can see it is saving it just fine to modx but when I do a select from the table itself its not updated at all. Any thoughts on where I went wrong
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Hmm nothing stands out as wrong there..

      Does the data in the database change at all? Or is it just the select that doesn't return the new data?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 38970
        • 59 Posts
        Hello,

        No the data in the database doesn't change at all I verified this with phpmyadmin. Any other thoughts ?