We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44231
    • 126 Posts
    hi there!

    I have encounter problems when updating my custom tables, I have this code
    if($select_pet !== 'add' && $select_pet !== 'no value'){
           
            $path = MODX_CORE_PATH . 'components/mod1/';
            $result = $modx->addPackage('mod1',$path . 'model/','mod_');
            
                $user_id = $_SESSION['logged'];
                $petname = $_POST['name-pet'];
                $petspec = $_POST['species-pet'];
                $petgen = $_POST['gen-pet'];
                $petage = $_POST['age-pet'];
                $petowner = $_POST['owner-name'];
            //echo $system_your_pet_id;
            
            if ($object = $modx->getObject('Tbluserpet',array('system_your_pet_id' => $system_your_pet_id))){
                             $object->set('vet_visited', $visits);
                             $object->set('vaccinations', $vaccin);
                             $object->set('treatments', $treat);
                             $object->set('consultation', $consult);
                             $object->set('appointments', $appoint);
                             $object->save(); 
                        }
                        else{
                            echo'error';
                        }
                        
                                if ($object = $modx->getObject('Userpetmedicalreport',array('system_pet_medical_id' => $system_pet_medical_id))){
                             $object->set('pet_name', $petname);
                             $object->set('pet_age', $petage);
                             $object->set('pet_gender', $petgen);
                             $object->set('owner_name', $petowner);
                             $object->set('pet_species', $petsepec);
                             $object->save(); 
                        }
                        else{
                            echo'error';
                        }
           
           //header("Location: http://tfv/");
           
           
       }


    this code works fine in other snippet but when I use it here it didn't
    what would be the problem?

    here is my schema
    modx 2.2.6 pl traditional

    <object class="Tbluseranimal" table="tbluseranimal" extends="xPDOObject">
    		<field key="system_animal_interest_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
    		<field key="id_animal" dbtype="int" precision="11" phptype="integer" null="false" />
    		<field key="system_user_id" dbtype="int" precision="11" phptype="integer" null="true" />
    		<field key="animal_interest" dbtype="varchar" precision="300" phptype="string" null="true" />
    
    		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
    			<column key="system_animal_interest_id" length="" collation="A" null="false" />
    		</index>
    	</object>
    <object class="Userpetmedicalreport" table="userpetmedicalreport" extends="xPDOObject">
    		<field key="system_pet_medical_id" dbtype="int" precision="11" phptype="integer" null="false" index="pk" />
    		<field key="system_user_id" dbtype="int" precision="11" phptype="integer" null="true" />
    		<field key="system_your_pet_id" dbtype="int" precision="11" phptype="integer" null="true" />
    		<field key="vet_visited" dbtype="varchar" precision="300" phptype="string" null="true" />
    		<field key="vaccinations" dbtype="varchar" precision="300" phptype="string" null="true" />
    		<field key="treatments" dbtype="varchar" precision="300" phptype="string" null="true" />
    		<field key="consultation" dbtype="varchar" precision="300" phptype="string" null="true" />
    		<field key="appointments" dbtype="varchar" precision="300" phptype="string" null="true" />
    
    		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
    			<column key="system_pet_medical_id" length="" collation="A" null="false" />
    		</index>
    	</object>


    thanks in advance!
    john
      • 28840
      • 46 Posts
      What do your logs tell you? MODx error report? Server error log?

      Where is here and other?

      Try putting the $object->save() function in IF statement like this:
      if($object->save() === false) echo 'Something went very very wrong<pre>'.print_r($object->toArray(),1);
      


      Sumoborac