3

Possible Duplicate:
Reference - What does this error mean in PHP?

I am having an issue with the following section of code:

I can get the error notices in the validation but the next step = valid code I just get a white page, Any Ideas?

I have checked the error settings and I have set it in the public_html php.ini file and I still don't get errors

function create_sale()
{       
$this->template->append_metadata( js('debounce.js', 'sales') );        
$this->template->append_metadata( js('new_sale.js', 'sales') );        

    // -------------------------------------
    // Validation & Setup
    // -------------------------------------

    $this->load->library('form_validation');

    $this->sale_rules[1]['rules'] .= '|callback__check_slug[insert]';

    $this->form_validation->set_rules( $this->sale_rules );

    foreach($this->sale_rules as $key => $rule)
    {
        $sale->{$rule['field']} = $this->input->post($rule['field'], TRUE);
    }

    // -------------------------------------
    // Process Data
    // -------------------------------------

    if ($this->form_validation->run())
    {
        if( ! $this->sales_m->insert_new_sale( $sale, $this->user->id ) ):
        {
            $this->session->set_flashdata('notice', lang('sales.new_sale_error'));  
        }
        else:
        {

            $this->session->set_flashdata('success', lang('sales.new_sale_success'));   
        }
        endif;

        redirect('admin/sales');
    }

    $this->template->set('sale', $sale)
                   ->build('admin/new');

}   
Community
  • 1
  • 1
Jess McKenzie
  • 8,345
  • 27
  • 100
  • 170

4 Answers4

4

You said that your code is valid but you get a white page.

Most of the time when you get a white page you will simply have an error in your code.

As is the case here:

You suddenly have an endif; in your code which you don't want there.

Enable error reporting please:

Include this code in your bootstrap file:

error_reporting(E_ALL);
ini_set("display_errors", 1);

Remember to disable this in production!

To remove the error change:

if ($this->form_validation->run())
{
    if( ! $this->sales_m->insert_new_sale( $sale, $this->user->id ) ):
    {
        $this->session->set_flashdata('notice', lang('sales.new_sale_error'));  
    }
    else:
    {

        $this->session->set_flashdata('success', lang('sales.new_sale_success'));   
    }
    endif;

    redirect('admin/sales');
}

to:

if ($this->form_validation->run())
{
    if( ! $this->sales_m->insert_new_sale( $sale, $this->user->id ) )
    {
        $this->session->set_flashdata('notice', lang('sales.new_sale_error'));  
    } else {
        $this->session->set_flashdata('success', lang('sales.new_sale_success'));   
    }

    redirect('admin/sales');
}
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
  • @PeeHaha, I have done your code and still a whitepage. In my config I have $config['sess_cookie_name'] = 'pyrocms' . (ENVIRONMENT !== 'dev' ? '_' . ENVIRONMENT : ''); in my index.php dev = error_reporting(E_ALL); ini_set('display_errors', 1); – Jess McKenzie Aug 25 '11 at 19:19
  • @Jess McKenzihi: If you still get a white page you should really check whether `admin/sales` page is outputting anything. What do you get when you go to that URL manually? – PeeHaa Aug 25 '11 at 19:32
  • I get the sales admin page it loads fine. – Jess McKenzie Aug 25 '11 at 19:59
  • @Jess McKenzie: can you `print('something')` just before the redirect. And also do a `print('something else'); exit();` at the top of the admin/sales page and tell me the result. – PeeHaa Aug 25 '11 at 20:23
  • I have done the print before the redirect still white and the top of the sales worked - I did them sep as I need to access the sales page to add a sale – Jess McKenzie Aug 25 '11 at 20:51
  • @Jess McKenzie: that's strange. However I might see a problem with your script. Add an `exit();` after the redirect. Or the script will continue to execute. So do this: `redirect('admin/sales'); exit();` – PeeHaa Aug 25 '11 at 20:55
  • Nope still white, wish I could get a **word** error! – Jess McKenzie Aug 25 '11 at 21:49
  • @JessMcKenzie let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2871/discussion-between-peehaa-and-jess-mckenzie) – PeeHaa Aug 25 '11 at 21:52
2

You have too many closing curly braces, remove the 'endif' in your script and it should work.

Ashley
  • 1,459
  • 2
  • 12
  • 25
1

CodeIgniter is notorious for the "white screen of death".

Generally when I've run into it, it's been because of the way they set up their database error handling (it's not good). Database errors aren't handled when $db['default']['db_debug'] is set to FALSE. Any query or connection attempt that fails just returns false. Execution continues after a bad query, which can result in a white screen of death. If you're lucky, you'll get an error message in the logs in some cases, but in most you won't, as the query() function just silently returns false without logging anything.

If you set it to TRUE, then you can be in an even worse position, because any database error will automatically result in CodeIgniter calling it's own show_error() function and generating a 500 HTTP response, and you have no chance of handling it on your own.

This is the most common way to get the WSOD that I'm aware of. I haven't used the 2.0 versions of CI, but it was the case in the 1.7 versions. You may want to try setting db_debug to true in your database.php config file until you find out what's going on.

zombat
  • 92,731
  • 24
  • 156
  • 164
0

I suspect that your redirect() is failing to redirect (instead just leaving a blank page sans redirect) for some reason or another. Toss a debug message before it to check.

τεκ
  • 2,994
  • 1
  • 16
  • 14