View Single Post
  #5  
Old 01-29-2016, 10:33 PM
FounderSim FounderSim is offline
Member
 
Join Date: Sep 2014
Posts: 65
Gender: Male
Credits: 7,838
FounderSim is on a distinguished road
Default

Here's how I debug some mysidia scripting I do. I add DIE's in the code to check on things. I added two DIE statements in your code.

Code:
public function index(){
        $mysidia = Registry::get("mysidia");        
        if($mysidia->input->post("submit")){
            $this->access = "member";
            $this->handleAccess();
            $id = $mysidia->input->post("id");
            if($mysidia->session->fetch("adopt") != 1 or !$id) throw new InvalidIDException("global_id");            
            
            $adopt = new Adoptable($id);
            $cost = $adopt->getCost();
DIE("COST: " . $cost); //delete after seeing result
            $usermoney = $mysidia->db->select("users", array("money"), "username = {$mysidia->user->username}")->fetchColumn();
DIE("MONEY: " . $usermoney); // delete after seeing result
            $newusermoney = $usermoney - $cost;
            $mysidia->db->update("users", array("money" => $newusermoney), "username='{$mysidia->user->username}'"); //this line updates money. I assume $cost is 0 since no subtracting is done.
            $conditions = $adopt->getConditions();
            if(!$conditions->checkConditions()) throw new NoPermissionException("condition");
            
            $name = (!$mysidia->input->post("name"))?"Unnamed":$mysidia->input->post("name");
            $alts = $adopt->getAltStatus();
            $code = $adopt->getCode();
            $gender = $adopt->getGender();
            $mysidia->db->insert("owned_adoptables", array("aid" => NULL, "type" => $adopt->getType(), "name" => $name, "owner" => $mysidia->user->username, "currentlevel" => 0, "totalclicks" => 0, "code" => $code, 
                                                           "imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'notfortrade', "isfrozen" => 'no', "gender" => $gender, "offsprings" => 0, "lastbred" => 0, "originalowner" => $mysidia->user->username, "birthday" => date("F jS, Y")  ));
                        
            $aid = $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
            $this->setField("aid", new Integer($aid));
            $this->setField("name", new String($name));            
            $this->setField("eggImage", new String($adopt->getEggImage()));
            return;
        }
__________________
Reply With Quote