CodeIgniter Forums

Full Version: Setting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Fatal error: Call to a member function result() on boolean in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\models\Mpages.php on line 197
A PHP Error was encountered
Severity: Error
Message: Call to a member function result() on boolean
Filename: models/Mpages.php
Line Number: 197
Backtrace:


Line 197:          //return $query->result();

        return $query->result_array();


I would like to update setting data:


models/Mpages.php


PHP Code:
    public function add_settings()
    {
        
        
$data = array(
            
'email' => $this->input->post('email'),
            
'site_name' => $this->input->post('sitename'),
            
'meta_title' => $this->input->post('title'),
            
'meta_keyword' => $this->input->post('keyword'),
            
'meta_description' => $this->input->post('description'),
            
'facebook' => $this->input->post('facebook'),
            
'twitter' => $this->input->post('twitter'),
            
'rss' => $this->input->post('rss')            
        );
        
        
$query $this->db->update('setting'$data);
        
//return $query->result();
        
return $query->result_array();
        
//return $this->db->update('setting', $data);
            
    




controllers/Cpages.php

PHP Code:
    public function settings() { 
    
        
$data['success_message'] = '';
    
        
$data['setting'] = $this->Mpages->call_settings();
        
        
$this->load->view('settings'$data); 
            
    } 


views/settings.php


PHP Code:
<?php echo $success_message?>
                        <?php echo validation_errors(); ?>
                        
                        <?php echo form_open('Cpages/updatesettings'); ?>                        
                        
                        <table border="0" style="width: 100%; height: 90px;">
                        
                        <?php foreach($setting as $setting_item): ?>
                        
                            <tr>
                                <td><b>Contact Information</b></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>Email</td>
                                <td><input type="text" name="email" value="<?php echo $setting_item['email']; ?>"></td>
                            </td>    
                            <tr>
                                <td>Site Name</td>
                                <td><input type="text" name="sitename" value="<?php echo $setting_item['site_name']; ?>"></td>
                            </td>
                            <tr>
                                <td></td>
                                <td><br></td>                                
                            </tr>    
                            <tr>
                                <td><b>Site Information</b></td>
                                <td></td>
                            </td>
                            <tr>
                                <td>Meta Title</td>
                                <td><input type="text" name="title" value="<?php echo $setting_item['meta_title']; ?>"></td>
                            </td>
                            <tr>
                                <td>Meta Keyword</td>
                                <td><input type="text" name="keyword" value="<?php echo $setting_item['meta_keyword']; ?>"></td>
                            </td>
                            <tr>
                                <td>Meta Description</td>
                                <td><input type="text" name="description" value="<?php echo $setting_item['meta_description']; ?>"></td>
                            </td>
                            <tr>
                                <td></td>
                                <td><br></td>                                
                            </tr>
                            <tr>
                                <td><b>Social Media Information</b></td>
                                <td></td>
                            </td>
                            <tr>
                                <td>Facebook</td>
                                <td><input type="text" name="facebook" value="<?php echo $setting_item['facebook']; ?>"></td>
                            </td>
                            <tr>
                                <td>Twitter</td>
                                <td><input type="text" name="twitter" value="<?php echo $setting_item['twitter']; ?>"></td>
                            </td>
                            <tr>
                                <td>RSS</td>
                                <td><input type="text" name="rss" value="<?php echo $setting_item['rss']; ?>"></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><br></td>                                
                            </tr>    
                            <tr>
                                <td></td>
                                <td><input type="submit" name="submit" class="edit" value="Submit"></td>
                            </tr>                    
                        
                        <?php endforeach ?>
                        
                        </table>            
                        </div> 
Fatal error: Call to a member function result_array() on boolean in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\models\Mpages.php on line 198
A PHP Error was encountered
Severity: Error
Message: Call to a member function result_array() on boolean
Filename: models/Mpages.php
Line Number: 198
Backtrace:


Line 198:      return $query->result_array();


Similar error still appears:

models/Mpages.php

PHP Code:
public function add_settings()
    {
        
        
$data = array(
            
'email' => $this->input->post('email'),
            
'site_name' => $this->input->post('sitename'),
            
'meta_title' => $this->input->post('title'),
            
'meta_keyword' => $this->input->post('keyword'),
            
'meta_description' => $this->input->post('description'),
            
'facebook' => $this->input->post('facebook'),
            
'twitter' => $this->input->post('twitter'),
            
'rss' => $this->input->post('rss')            
        );
        
        
$query $this->db->replace('setting'$data);
        
//return $query->result();
        
return $query->result_array();
        
            
    } 
A more specific user guide reference ... http://www.codeigniter.com/user_guide/da...r::replace

query->replace(...) returns a boolean.

This was obvious in your original post ... the error message on the very first line.
Fatal error: Call to a member function replace() on boolean in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\models\Mpages.php on line 199
A PHP Error was encountered

Severity: Error

Message: Call to a member function replace() on boolean

Filename: models/Mpages.php

Line Number: 199

Backtrace:

Line 199: return $query->replace();
PHP Code:
public function update_settings($id) {     
    $data 
= array(
        'email' => $this->input->post('email'),
        'site_name' => $this->input->post('sitename'),
        'meta_title' => $this->input->post('title'),
        'meta_keyword' => $this->input->post('keyword'),
        'meta_description' => $this->input->post('description'),
        'facebook' => $this->input->post('facebook'),
        'twitter' => $this->input->post('twitter'),
        'rss' => $this->input->post('rss')            
    
);
        
   $this
->db->where('id'$id); // could be users login id what ever you need     
   $this->db->update('setting'$data);    



Then use a separate model function to get the data
All query that change the data in a table  return the result of the operation not the data.
To solve your issue you need something like this


PHP Code:
$result $this->db->update('setting'$data);
if(
$result) {
 
  return $this->db->get_where('setting',array('id' => $id));
}
else {
 
  return 'The update was not successful most likely because I am freaking useless and cannot write any code';