CodeIgniter Forums
Sometimes blank page when performing update query, refreshing the page fixes the problem. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Sometimes blank page when performing update query, refreshing the page fixes the problem. (/thread-40668.html)



Sometimes blank page when performing update query, refreshing the page fixes the problem. - El Forum - 04-15-2011

[eluser]Met[/eluser]
Hi,

I haven't run in to this problem before, but here's my update code:

Code:
public function visibility($id = null, $action = null)
    {
        if ($action == 'hide') {
            $visible = 0;
        } elseif ($action == 'show') {
            $visible = 1;
        }
        $data = array(
                       'visible' => $visible,
                       'modified' => date('Y-m-d H:i:s')
                    );
        
        $this->db->where('id', $id);
        $this->db->update('tbl_items', $data);
        echo $this->db->affected_rows();
    }


Pretty standard stuff. I have enabled logging, and here is the only output:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

DEBUG - 2011-04-15 12:42:15 --> Config Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Hooks Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Utf8 Class Initialized
DEBUG - 2011-04-15 12:42:15 --> UTF-8 Support Enabled
DEBUG - 2011-04-15 12:42:15 --> URI Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Router Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Output Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Input Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Global POST and COOKIE data sanitized
DEBUG - 2011-04-15 12:42:15 --> Language Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Loader Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Helper loaded: url_helper
DEBUG - 2011-04-15 12:42:15 --> Database config for development environment is not found. Trying global config.
DEBUG - 2011-04-15 12:42:15 --> Database Driver Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Model Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Model Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Controller Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Helper loaded: form_helper
DEBUG - 2011-04-15 12:42:15 --> Helper loaded: admin_tile_helper
DEBUG - 2011-04-15 12:42:15 --> Helper loaded: tile_helper
DEBUG - 2011-04-15 12:42:15 --> Model Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Form Validation Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Session Class Initialized
DEBUG - 2011-04-15 12:42:15 --> Helper loaded: string_helper
DEBUG - 2011-04-15 12:42:15 --> Session routines successfully run
DEBUG - 2011-04-15 12:42:15 --> Table Class Initialized
DEBUG - 2011-04-15 12:42:15 --> File loaded: application/views/admin/header.php
DEBUG - 2011-04-15 12:42:15 --> File loaded: application/views/admin/footer.php
DEBUG - 2011-04-15 12:42:15 --> File loaded: application/views/admin/manage_view.php
DEBUG - 2011-04-15 12:42:15 --> Language file loaded: language/english/profiler_lang.php
DEBUG - 2011-04-15 12:42:15 --> Helper loaded: text_helper
DEBUG - 2011-04-15 12:42:15 --> Final output sent to browser
DEBUG - 2011-04-15 12:42:15 --> Total execution time: 0.1916

again - nothing unusual.

I have checked my Apache log and there are no errors - so what could be causing this behaviour?

To reiterate - sometimes the update will work fine, other times I get a blank page. When I refresh, the query is run.

I have output profiling on, and when the page is blank, there is no output at all. I also have error messages turned on - there is just nothing.

I can provide further information if needed.

Thank you.

** I'm not using caching. **


Sometimes blank page when performing update query, refreshing the page fixes the problem. - El Forum - 04-15-2011

[eluser]carbona[/eluser]
If your $action is not equal with "show" or "hide" then $visible will not be defined and you will have an error in your query.

You can fix this in 2 ways :

1.change $action variable default valut to hide or show instead of null
Code:
public function visibility($id = null, $action = hide)
    {
        if ($action == 'hide') {
            $visible = 0;
        } elseif ($action == 'show') {
            $visible = 1;
        }
        $data = array(
                       'visible' => $visible,
                       'modified' => date('Y-m-d H:i:s')
                    );
        
        $this->db->where('id', $id);
        $this->db->update('tbl_items', $data);
        echo $this->db->affected_rows();
    }

2. initialize $visible variable
Code:
public function visibility($id = null, $action = null)
    {
        $visible = 0;
        if ($action == 'hide') {
            $visible = 0;
        } elseif ($action == 'show') {
            $visible = 1;
        }
        $data = array(
                       'visible' => $visible,
                       'modified' => date('Y-m-d H:i:s')
                    );
        
        $this->db->where('id', $id);
        $this->db->update('tbl_items', $data);
        echo $this->db->affected_rows();
    }

--carbona


Sometimes blank page when performing update query, refreshing the page fixes the problem. - El Forum - 04-15-2011

[eluser]Met[/eluser]
thanks for the reply. I should say that, the parameters will always have values, and indeed in my tests, they have values as well. Besides, this would show an error of sorts if it were the case - I just get a blank screen.