Sunil Kashyap
Sunil Kashyap

Reputation: 2984

Call to a member function select() on a non-object

im trying to call select query through 'fund' class extended 'DB' class and select query is in DB class... i made fundinst() function and call select function by making fund class object... but it shows fatal error...

 function fundinst(){
    //echo "in fundinst()";exit;
    //echo $previous_month;exit;
    //echo $current_month;exit;
    //$funds = new funds;
    $probal = $funds->select($funds->table,'',"user_id = '".$_POST['user_id']."' and month = '".$previous_month."'");
    if(isset($probal[0]["crt_bal"]) && $probal[0]["crt_bal"]!=''){
    //print_r($probal);exit;
    $_POST["crt_bal"] = $probal[0]["crt_bal"] + $_POST["total"];
    //$inst = ($probal[0]["curInst"] * $probal[0][rateInst])/12 * 100;
    //echo $prograssive;
    }else{$_POST["crt_bal"] =$_POST["total"];}
    $_POST['created'] = date("Y-m-d h:i:sa");
    if($funds->save($funds->table,$_POST))
    {
        $_POST["curInst"] = ($_POST["balance"] * $rateInst)/ 12 * 100;
        $f_year->save($f_year->table,$_POST);
        echo "Save successfully";
    }
    else{echo "failed";}
}

this is fund class code

class funds extends DB
{
    var $table = "funds";   
}

Upvotes: 0

Views: 604

Answers (1)

Minesh Patel
Minesh Patel

Reputation: 541

You Have extended class DB, so use

$this

instead of $funds

function fundinst(){

    $probal = $this->select($this->table,'',"user_id = '".$_POST['user_id']."' and month = '".$previous_month."'");
    if(isset($probal[0]["crt_bal"]) && $probal[0]["crt_bal"]!=''){

    $_POST["crt_bal"] = $probal[0]["crt_bal"] + $_POST["total"];

    }else{$_POST["crt_bal"] =$_POST["total"];}
    $_POST['created'] = date("Y-m-d h:i:sa");
    if($this->save($this->table,$_POST))
    {
        $_POST["curInst"] = ($_POST["balance"] * $rateInst)/ 12 * 100;
        $f_year->save($f_year->table,$_POST);
        echo "Save successfully";
    }
    else{echo "failed";}
}

Upvotes: 1

Related Questions