Welcome Guest, Not a member yet? Register   Sign In
fatal error:Call to a member function query()
#1

[eluser]praveenarya[/eluser]
hi all,
iam new to ci iam developing a site in ci i got this error.my code is
Code:
if($_SERVER['REQUEST_METHOD']=="POST")
    {
        $ssss="select * from ab_admin where ad_uname='".$_POST['log_id']."' and ad_pass='".$_POST['log_pswd']."' and ad_status=1";
    $query=$this->db->query($ssss);
    
if ($this->db->num_rows() > 0)
{

foreach ($this->db->result_array() as $row)
{
.........//do something
}
}
}
but i got error
Fatal error: Call to a member function query() on a non-object in D:\wamp\www\example\system\application\controllers\admin\welcome.php on line 17
can anyone help me
thanks in advance
#2

[eluser]Dam1an[/eluser]
Have you loaded the database? Either manually, or in the autoload file?
#3

[eluser]praveenarya[/eluser]
ya thanks for fast reply i got it i auto loaded it instead manually but
when loading error message it behaving stange
mycode is
Code:
if($_SERVER['REQUEST_METHOD']=="POST")
    {
        $ssss="select * from ab_admin where ad_uname='".$_POST['log_id']."' and ad_pass='".$_POST['log_pswd']."' and ad_status=1";
    $query=$this->db->query($ssss);
    //$query = $this->db->query("select * from `ab_admin` where ad_uname='".$_POST['log_id']."' and ad_pass='".$_POST['log_pswd']."' and ad_status=1");

if ($query->num_rows() > 0)
{

foreach ($query->result_array() as $row)
{
//if sucess then
$this->load->view('admin/welcome');
} }else {
$data['msg']="InValid Login Details";
    
    $this->load->view('admin/welcome_message',$data);
}

}

i got two pages one normal one and one with error message set

what i did wrong please correct me
thanks in advance
#4

[eluser]mariek[/eluser]
did you set the active record to TRUE ?
in the database configuration, l. 38 :
$active_record = TRUE;
#5

[eluser]praveenarya[/eluser]
yes,it is set to true
#6

[eluser]MindFeed[/eluser]
If you can post your complete model code, that might help!

Thanks,
Bhargav Khatana
#7

[eluser]praveenarya[/eluser]
sure here is my code
Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('admin/welcome_message');
        
        if($_SERVER['REQUEST_METHOD']=="POST")
    {
        $ssss="select * from ab_admin where ad_uname='".$_POST['log_id']."' and ad_pass='".$_POST['log_pswd']."' and ad_status=1";
    $query=$this->db->query($ssss);
    //$query = $this->db->query("select * from `ab_admin` where ad_uname='".$_POST['log_id']."' and ad_pass='".$_POST['log_pswd']."' and ad_status=1");

if ($query->num_rows() > 0)
{

foreach ($query->result_array() as $row)
{

    
            session_unregister("ab_username");
            session_unregister("ab_dispname");
            session_unregister("ab_id");
            session_unregister("ab_type");    
            //session_unregister("ab_email");
            session_register("ab_username");
            session_register("ab_dispname");
            session_register("ab_id");
            session_register("ab_type");
        
            $_SESSION['ab_username']=$log_row['ad_uname'];
            $_SESSION['ab_dispname']=$log_row['ad_dispname'];
            $_SESSION['ab_id']=$log_row['ad_id'];
            $_SESSION['ab_type']=$log_row['ad_admin_type'];
        //$_SESSION['ab_email']=$log_row['ad_email'];
        
            if($log_row['ad_master']=='1'){ session_unregister("ad_master"); session_register("ad_master"); $_SESSION['ad_master']='yes';}
            if($log_row['ad_book']=='1'){ session_unregister("ad_book"); session_register("ad_book"); $_SESSION['ad_book']='yes';}
            if($log_row['ad_travel']=='1'){ session_unregister("ad_travel"); session_register("ad_travel"); $_SESSION['ad_travel']='yes';}
            if($log_row['ad_cms']=='1'){ session_unregister("ad_cms"); session_register("ad_cms"); $_SESSION['ad_cms']='yes';}
            if($log_row['ad_user_manage']=='1'){ session_unregister("ad_user_manage"); session_register("ad_user_manage"); $_SESSION['ad_user_manage']='yes';}
            if($log_row['ad_newsletter']=='1'){ session_unregister("ad_newsletter"); session_register("ad_newsletter"); $_SESSION['ad_newsletter']='yes';}
            if($log_row['ad_ads']=='1'){ session_unregister("ad_ads"); session_register("ad_ads"); $_SESSION['ad_ads']='yes';}
        $this->load->view('admin/welcome');
        }
    }else {
    
    $data['errmsg']="Invalid Login Details";
    $this->load->view('admin/welcome_message',$data);
        }
        }
        
    }
}


and in view page i wrote
Code:
if(isset($errmsg)) { echo $errmsg;}
#8

[eluser]MindFeed[/eluser]
Can you please write following line in first place at your index() function and see if database object been created and assigned to CI or not ?

Code:
print "<pre>"; print_r($this);exit;

you should see something like this, [that's oracle I am using, you might see relevant result]

Code:
[db] => CI_DB_oci8_driver Object
        (
            [dbdriver] => oci8
            [_escape_char] => "
            [_count_string] => SELECT COUNT(1) AS
            [_random_keyword] =>  ASC
            [_commit] => 32
            [stmt_id] =>
            [curs_id] =>
            [limit_used] =>
            [error] =>

If not can you please try loading database with the following line in your constructor.

Code:
$this->load->database();


Post the behavior and error if any !

Thanks,
Bhargav




Theme © iAndrew 2016 - Forum software by © MyBB