⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Missing error message on update



Smilie
  • profile picture
  • Member

Posted 23 May 2013 - 06:24 AM

Hi,

When I try to update one of my records I receive neither a confirmation message nor a failure message.

The row remains unchanged.

 

Is there any tips on how I can get the error message?

 

This is my database:

http://i.imgur.com/qmssp5e.png

 

This is my code:

[spoiler]

<?php
ini_set('display_errors', '1');
class User extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        if (!$this->general->isLoggedIn()) {
            header('Refresh: 0; url=' . base_url("login") . '');
            die();
        }

        if (!$this->general->checkAccess("users")) {
            header('Refresh: 0; url=' . base_url("denied") . '');
            die();
        }
        $this->load->library('grocery_CRUD');
        $this->load->library('ipbwi/ipbwi');
    }

    function index() {
        $this->userlist();
    }

    function userlist() {

        if (!$this->general->isLoggedIn()) {
            header('Refresh: 0; url=' . base_url("login") . '');
            die();
        }

        if (!$this->general->checkAccess("users")) {
            header('Refresh: 0; url=' . base_url("denied") . '');
            die();
        }


        $crud = new grocery_CRUD();

        $crud->set_table('users')
            ->set_subject('Users')
            ->columns('username','email', 'firstname', 'lastname')
            ->display_as('username','User name')
            ->display_as('email','Email')
            ->display_as('firstname','First name')
            ->display_as('lastname','Last name');

        $crud->callback_before_update(array($this,'encrypt_password_callback'));
        $crud->callback_edit_field('password',array($this,'set_password_input_to_empty'));
        $crud->callback_before_update(array($this,'check_admin_callback'));
        $crud->set_rules('email', 'Email', 'required|valid_email');
        $crud->set_rules('comission_percent', 'Comission percent', 'is_natural|less_than[101]');
        $crud->unset_print();
        $crud->unset_export();
        $crud->unset_delete();
        $crud->unset_add();
        $crud->set_relation('country_id','countries','name');
        $crud->fields('username', 'email', 'password', 'firstname', 'lastname', 'exclusive_author',
                        'firmname', 'country_id', 'profile_title', 'profile_desc', 'featured_author', 'referals', 'register_datetime',
                        'ip_address', 'status', 'comission_percent');
        $crud->required_fields('email', 'firstname', 'lastname', 'exclusive_author',
            'country_id', 'featured_author', 'referals', 'status', 'firmname');
        $crud->display_as('firmname','Company')->display_as('profile_desc','Profile description')
             ->display_as('profile_desc','Profile description')->display_as('register_datetime','Registered')
             ->display_as('ip_address','IP')->display_as('country_id','Country');

        $crud->field_type('username', 'readonly');
        $crud->field_type('ip_address', 'readonly');
        $crud->field_type('register_datetime', 'readonly');

        // Pass grid to the view
        $data['page_grid'] = $crud->render();


        $data['page'] = 'user';
        $view = $this->load->view('user/userlist', $data, TRUE);
        $this->template->create_page('Users', $view);
    }

    public function encrypt_password_callback($post_array,$primary_key) {
        if($post_array['password'] == '')
        {
            unset($post_array['password']);
            return $post_array;
        }
        $post_array['password'] = md5(md5($post_array['password']));
        $this->ipbwi->member->updatePassword ($post_array['password'], $this->general->userIdToUsername($primary_key));
        $this->ipbwi->member->updateMember(array('email' => $post_array['email']), $this->general->userIdToUsername($primary_key));

        return $post_array;
    }

    function log_user_after_update($post_array,$primary_key)
    {
//        $user_logs_update = array(
//            "user_id" => $primary_key,
//            "last_update" => date('Y-m-d H:i:s')
//        );
//
//        $this->db->update('user_logs',$user_logs_update,array('user_id' => $primary_key));

        return true;
    }


    function set_password_input_to_empty() {
        return "<input type='password' name='password' value='' />";
    }


    public function check_admin_callback($primary_key)
    {
        $username = $this->general->userIdToUsername($primary_key);
        if($this->ipbwi->group->isInGroup(7, $this->ipbwi->member->name2id($username), true))
            return false;
        else
            return true;

    }

}

?>

[/spoiler]

 

I have attempted to comment out all callbacks, still no luck, and it is working perfectly on other databases.


davidoster
  • profile picture
  • Member

Posted 23 May 2013 - 08:22 AM

The problem is at the public function encrypt_password_callback($post_array,$primary_key).

I am not familiar with the library ipbwi, but it seems as you are updating the user's record within the callback!

This is not allowed! The callback must be used to change the field and/or field value and return.

 

Try this,

public function encrypt_password_callback($post_array,$primary_key) {
        if($post_array['password'] == '')
        {
            unset($post_array['password']);
            return $post_array;
        }
        $post_array['password'] = md5(md5($post_array['password']));
        //$this->ipbwi->member->updatePassword ($post_array['password'], $this->general->userIdToUsername($primary_key));
        //$this->ipbwi->member->updateMember(array('email' => $post_array['email']), $this->general->userIdToUsername($primary_key));

        return $post_array;
    }

Smilie
  • profile picture
  • Member

Posted 23 May 2013 - 14:00 PM

Hi,

I have tried to comment out the callbacks, so this cannot be the problem.

 

The ipbwi is updating an entirely different user in another database, so it shouldn't be the problem.


davidoster
  • profile picture
  • Member

Posted 24 May 2013 - 05:58 AM

Hmmm! Then it has to do with the validation rules. One (or all) of your validation rules stops the record from being updated.


Smilie
  • profile picture
  • Member

Posted 24 May 2013 - 07:15 AM

Okay, I tried to comment as much as possible

[spoiler]

    function userlist() {

        if (!$this->general->isLoggedIn()) {
            header('Refresh: 0; url=' . base_url("login") . '');
            die();
        }

        if (!$this->general->checkAccess("users")) {
            header('Refresh: 0; url=' . base_url("denied") . '');
            die();
        }


        $crud = new grocery_CRUD();

        $crud->set_table('users')
            ->set_subject('Users')
            ->columns('username','email', 'firstname', 'lastname')
            ->display_as('username','User name')
            ->display_as('email','Email')
            ->display_as('firstname','First name')
            ->display_as('lastname','Last name');

//        $crud->callback_before_update(array($this,'encrypt_password_callback'));
//        $crud->callback_edit_field('password',array($this,'set_password_input_to_empty'));
//        $crud->callback_before_update(array($this,'check_admin_callback'));
//        $crud->set_rules('email', 'Email', 'required|valid_email');
//        $crud->set_rules('comission_percent', 'Comission percent', 'is_natural|less_than[101]');
        $crud->unset_print();
        $crud->unset_export();
        $crud->unset_delete();
        $crud->unset_add();
        $crud->set_relation('country_id','countries','name');
        $crud->fields('username', 'email', 'password', 'firstname', 'lastname', 'exclusive_author',
                        'firmname', 'country_id', 'profile_title', 'profile_desc', 'featured_author', 'referals', 'register_datetime',
                        'ip_address', 'status', 'comission_percent');
        //$crud->required_fields('email', 'firstname', 'lastname', 'exclusive_author',
        //    'country_id', 'featured_author', 'referals', 'status', 'firmname');
        $crud->display_as('firmname','Company')->display_as('profile_desc','Profile description')
             ->display_as('profile_desc','Profile description')->display_as('register_datetime','Registered')
             ->display_as('ip_address','IP')->display_as('country_id','Country');

        $crud->field_type('username', 'readonly');
        $crud->field_type('ip_address', 'readonly');
        $crud->field_type('register_datetime', 'readonly');

        // Pass grid to the view
        $data['page_grid'] = $crud->render();


        $data['page'] = 'user';
        $view = $this->load->view('user/userlist', $data, TRUE);
        $this->template->create_page('Users', $view); 

[/spoiler]

 

There are no validation as far as I can see now, and it still fails :(

Perhaps it could be "not null" in the database? - It's very difficult as no error message is shown.


davidoster
  • profile picture
  • Member

Posted 24 May 2013 - 07:23 AM

Why don't you check the log files?

1. log files from CodeIgniter

2. log files from the Apache

 

Check this post to see how to enable/use them.


Smilie
  • profile picture
  • Member

Posted 24 May 2013 - 08:18 AM

Great, I'm afraid it's related to either the framework, or the way I use it though:

 

 
DEBUG - 2013-05-24 08:17:21 --> DB Transaction Failure
ERROR - 2013-05-24 08:17:21 --> Query error: Unknown column 'Array' in 'where clause'

davidoster
  • profile picture
  • Member

Posted 24 May 2013 - 08:39 AM

The only thing that I can suggest is to disable (for testing purposes) everything that has to do with ipbwi and see if the problem perists.

Remark this $this->load->library('ipbwi/ipbwi');

and the subsequent calls and see if this fixes the problem.

 

Also check this $this->general

if it generates same erroneous queries.


Smilie
  • profile picture
  • Member

Posted 24 May 2013 - 10:30 AM

It appears that I cannot have it call multiple methods back.. Silly me

 

So I have my function

[spoiler]

public function encrypt_password_callback($post_array, $primary_key) {
        if($post_array['password'] == '')
        {
            unset($post_array['password']);
            return $post_array;
        }
        echo $post_array;
        $post_array['password'] = md5(md5($post_array['password']));
        $this->ipbwi->member->updatePassword ($post_array['password'], $this->general->userIdToUsername($primary_key));
        $this->ipbwi->member->updateMember(array('email' => $post_array['email']), $this->general->userIdToUsername($primary_key));

        return $post_array;
    }

[/spoiler]

I would like to do some checks on primary key, as some may not be edited.

If the case is, that the user should NOT edit a particular row, I would like to show an error message, and halt the edit operation, any idea on how I can do this?