Welcome Guest, Not a member yet? Register   Sign In
Having some session issues, and could use a quick hand
#1

[eluser]draconus[/eluser]
I created this form a while ago, and it worked well for quite a while, but somewhere along the way i broke it, and i can't figure out what the issue is.

Here is my model for this:

Code:
function update(){
        $form = array(
            'id' => $this->input->post('id'),
            'firstName' => $this->input->post('firstName'),
            'lastName' => $this->input->post('lastName'),
            'address' => $this->input->post('address'),
            'address2' => $this->input->post('address2'),
            'city' => $this->input->post('city'),
            'state' => $this->input->post('state'),
            'country' => $this->input->post('country'),
            'postal' => $this->input->post('postal'),
            'home' => $this->input->post('home'),
            'business' => $this->input->post('business'),
            'cell' => $this->input->post('cell'),
            'email' => $this->input->post('email'),
            'activated' => $this->input->post('activated'),
            'practitioner' => $this->input->post('practitioner'),
            'administrator' => $this->input->post('administrator'),
            'profile' => $this->input->post('profile')
         );
        $this->db->where('id', $form['id']);
        $this->db->update('users', $form);

        $sql = ("SELECT * FROM users where id = '$form[id]' and activated = 1");
        $query = $this->db->query($sql);
        return ($query->num_rows() > 0) ? $query->row_array() : FALSE;        
    }

and here is my controller code:

Code:
function update(){
        $this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
        $data['title'] = ".:Conta Administra&ccedil;&atilde;o:.";    
        $id = $this->session->userdata('id');        
        
        if (!$this->session->userdata('activated')){
            $data['error'] = "1";
            $data['message'] = "Acesso negado, acesse a continuar...";
            $data['body'] = "";                    
            $this->load->view('index', $data);
        }else{    
            if ($this->form_validation->run() == FALSE){
                $this->load->model('user');
                $query = $this->user->get($id);
                $this->load->view('member/update', $query);
            }else{
                $this->load->model('user');
                $data = $this->user->update();                
                $this->session->set_userdata($data);
                $data['notice'] = "1";
                $data['message'] = "Seu perfil foi atualizado...";                    
                $this->load->view('member/profile', $data);
            }
        }                
    }

The profile page of course pulls the information from the session.

The error messages I am getting aren't very helpful, as they don't point to the issue within my code, but rather the builtin session library:

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: libraries/Session.php

Line Number: 457



A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Users/draconus/Sites/brazil/system/libraries/Exceptions.php:164)

Filename: libraries/Session.php

Line Number: 662


Any help would be greatly appreciated.
#2

[eluser]draconus[/eluser]
I would also like to note that the line that is supposed to update the session in the controller. It does not appear to be updating the userdata as it should.
#3

[eluser]gyo[/eluser]
Check if any of your scripts end up with a space after the closing tag ?&gt;
It should be completely deleted tho, as CI suggests.

If you're using some 3rd-party Session library, try to use the default instead.

Hope it helps!
#4

[eluser]pistolPete[/eluser]
function set_userdata() expects either a string or an array.
But function update() can return FALSE which is then passed to set_userdata():
Code:
return ($query->num_rows() > 0) ? $query->row_array() : FALSE;

Why do you query the database at all?
You could use:
Code:
(...)
        $this->db->where('id', $form['id']);
        $this->db->update('users', $form);

        return $form;
    }
#5

[eluser]draconus[/eluser]
But if I don't do it from the model, then the form array needs to be set in the controller, which at that point needs to be extracted to the model, as setting form post data needs to be done as an array.
#6

[eluser]pistolPete[/eluser]
Maybe my last post was a bit doubtful.

Quote:Why do you query the database at all?

I meant:

In the model's function update() you update a database entry.
After that you retrieve the same data again! This second database query is superfluous.

The model function would then look like:
Code:
function update(){
        $form = array(
            'id' => $this->input->post('id'),
           (...)
            'profile' => $this->input->post('profile')
         );
        $this->db->where('id', $form['id']);
        $this->db->update('users', $form);

        return $form;  
    }




Theme © iAndrew 2016 - Forum software by © MyBB