Welcome Guest, Not a member yet? Register   Sign In
I'm getting 3 errors (Undefined offset, trying to get property of non-objetc,... Please help
#1

[eluser]Aladin[/eluser]
Hello,
I'm trying to create a website with 3 type of membership, but when I added a code to the login function it puzzled me with 3 errors:

Quote:Message: Undefined offset: 1 (line 34)
Message: Trying to get property of non-object (line 34)
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Projects\Avocats\system\core\Exceptions.php:170)
Filename: helpers/url_helper.php

Line Number: 543

This is the code:
Code:
function login_process($login, $pass)
    {
        $sql = $this->db->get_where('avocats', array('login'=>$login, 'pass'=>$pass));
        if($sql->num_rows()==0) return false;
        else
        {
            $result = $sql->result();
            $avocatID = $result[0]->id;
            $avocatStatus = $result[1]->status;
                        
            if($avocatStatus=="pfp") redirect('espace_avocat/compte_pfp');
            if($avocatStatus=="pending") redirect('espace_avocat/compte_p');
            if($avocatStatus=="active")    return $avocatID;
            else
            {
                redirect('membres/inscription_avocat');
            }
        }
Thank you in advance and sorry if any english mistake I'm francophone.

EDIT 1
Line 34 is
Code:
$avocatStatus = $result[1]->status;
#2

[eluser]tintamarre[/eluser]
Hello,

usually, the Message: Undefined offset: 1 (line 34) error is because the index 1 does not exist on your array.

I would go in this direction...

T.
#3

[eluser]Aladin[/eluser]
Yes but how to fix it? I've tried
Code:
$avocatStatus = $result['status']->status;
I get the same error: Undefined index: status ??

Please anyone can help?
#4

[eluser]tintamarre[/eluser]
Did you declare your Array before ?
Code:
$result = Array ();
#5

[eluser]Aladin[/eluser]
It's getting worse, now in addition a Message: Trying to get property of non-object is added to the list.
What I want is that the script checks the status from the table then do the comparison below. Is there anything wrong with it?
#6

[eluser]John_Betong_002[/eluser]
Try this:

Run your browser
note results and script line
remove debug die();
repeat until error found.


Code:
function login_process($login, $pass)
{
    
    $sql = $this->db->get_where('avocats', array('login'=>$login, 'pass'=>$pass));
    
    echo  '<br />num: '    .$this->db->last_query();
echo '<br />line: ' .__LINE__;die;    

    echo '<br />num: '    .$sql->num_rows();
echo '<br />line: ' .__LINE__;die;    
    
    if($sql->num_rows() < 1)
    {
        return false;
        
    }else{
        $result = $sql->result();
        
        echo '<pre>';
            print_r($result);
        echo '</pre>';
echo '<br />line: ' .__LINE__;die;    
        
        $avocatID = $result[0]->id;
echo '<br />line: ' .__LINE__;die;    

        $avocatStatus = $result[1]->status;
echo '<br />line: ' .__LINE__;die;    
                    
        if($avocatStatus=="pfp")
            redirect('espace_avocat/compte_pfp');
            
        if($avocatStatus=="pending")
            redirect('espace_avocat/compte_p');
            
        if($avocatStatus=="active")
        {
            return $avocatID;
        }else{
          redirect('membres/inscription_avocat');
        }
    }
#7

[eluser]jmadsen[/eluser]
I think you are confusing


Code:
result();

with

Code:
row();

look at the examples from http://ellislab.com/codeigniter/user-gui...sults.html

Code:
$query = $this->db->query("YOUR QUERY");

foreach ($query->result_array() as $row)
{
   echo $row['title'];
   echo $row['name'];
   echo $row['body'];
}




Theme © iAndrew 2016 - Forum software by © MyBB