Welcome Guest, Not a member yet? Register   Sign In
Edit Pages
#11

Davy,
With these basic php questions, I recommend trying to post your questions here:

http://www.codingforums.com/php/
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#12

Put this code right above <?php foreach ($pages as $pages_item): ?>:
PHP Code:
echo '<pre>';
print_r($pages);
echo 
'</pre>';
die(); 
This will output the value of the $pages variable.
Good chance it's empty, and by no means an array. Because your model returns this:
PHP Code:
return $this->db->update('pages'$data); 
I guess the result is either true or false, but not the array with pages your want.

Now that I've put you on the right track, I hope you will solve the rest of the problem on your own. Don't keep asking the same (type of) questions over and over again.
Reply
#13

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:



controllers/Cpages.php

PHP Code:
public function updatesettings() {
        
        
$this->load->helper('form');
        
$this->load->library('form_validation');
        
        
$this->form_validation->set_rules('email''Email''required');
        
$this->form_validation->set_rules('sitename''Sitename''required');
        
$this->form_validation->set_rules('title''Title''required');
        
$this->form_validation->set_rules('keyword''Keyword''required');
        
$this->form_validation->set_rules('description''Description''required');
        
$this->form_validation->set_rules('facebook''Facebook''required');
        
$this->form_validation->set_rules('twitter''Twitter''required');
        
$this->form_validation->set_rules('rss''RSS''required');
        
                
        if (
$this->form_validation->run() === FALSE)
        {    
// return to first 
        
            
$data['success_message'] = "";
            
            
$this->load->view('settings'$data);
        }    
        else
        {
            
$data['success_message'] = "Setting has been successfully updated!";    
            
            
$data['setting'] = $this->Mpages->add_settings();
            
$this->load->view('settings'$data);
            
        }
    
    } 


views/settings.php

PHP Code:
<div class="widget-box">
                        <
div class="widget-title"><h5>Settings</h5></div>
                        <
div class="widget-content">
                        
                        <?
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>
                        
                    </div> 



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();
        
            
    } 
" If I looks more intelligence please increase my reputation."
Reply
#14

And what do you think that the Query Builder is returning for the update method? Maybe look at the CI code!

It sure is not returning an array.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#15

I update it into something else:

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_array();
        
            
    } 

There is a new error that I do not know how to fix it:

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 197
A PHP Error was encountered
Severity: Error
Message: Call to a member function result_array() on boolean
Filename: models/Mpages.php
Line Number: 197
Backtrace:
" If I looks more intelligence please increase my reputation."
Reply
#16

It's useless. Davy has pm'd me, we've all tried to tell him what to do but it's not getting to him. We've all been pretty patient, but Davy doesn't want to learn, he wants us to code for him. Can't help someone who doesn't want to be helped.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#17

(This post was last modified: 08-28-2016, 09:57 PM by ciadmin.)

$query = $this->db->update('setting', $data); ... this returns a boolean, which means that
$query->result_array(); will blow up with exactly the error message you report, because $query is not an object.

See http://www.codeigniter.com/user_guide/da...er::update
Reply
#18

Well, in that case I do not know how to use the boolean.  I try this printing out echo to proof if it is successful.


views/settings.php


PHP Code:
<div class="widget-box">
                        <
div class="widget-title"><h5>Settings</h5></div>
                        <
div class="widget-content">
                        
                        <?
php 
                        
                        
if($setting === TRUE){
                            
                            echo 
"Update has been successful."
                            
                        
}



                        
?>
                        
                        <?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> 



controllers/Cpages.php


PHP Code:
public function updatesettings() {
        
        
$this->load->helper('form');
        
$this->load->library('form_validation');
        
        
$this->form_validation->set_rules('email''Email''required');
        
$this->form_validation->set_rules('sitename''Sitename''required');
        
$this->form_validation->set_rules('title''Title''required');
        
$this->form_validation->set_rules('keyword''Keyword''required');
        
$this->form_validation->set_rules('description''Description''required');
        
$this->form_validation->set_rules('facebook''Facebook''required');
        
$this->form_validation->set_rules('twitter''Twitter''required');
        
$this->form_validation->set_rules('rss''RSS''required');
        
                
        if (
$this->form_validation->run() === FALSE)
        {    
// return to first 
        
            
$data['success_message'] = "";
            
            
$this->load->view('settings'$data);
        }    
        else
        {
            
$data['success_message'] = "Setting has been successfully updated!";    
            
            
$data['setting'] = $this->Mpages->add_settings();
            
$this->load->view('settings'$data);
            
        }
    
    } 
" If I looks more intelligence please increase my reputation."
Reply
#19

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: setting
Filename: views/settings.php
Line Number: 47
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\settings.php
Line: 47
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 567
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once


A PHP Error was encountered
Severity: Notice
Message: Undefined variable: setting
Filename: views/settings.php
Line Number: 66
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\settings.php
Line: 66
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 567
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once


A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/settings.php
Line Number: 66
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\settings.php
Line: 66
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 567
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once


views/settings.php


PHP Code:
<?php 
                        
                        
if($setting === TRUE)
                        
                        {
                            
                            echo 
"Update has been successful.";
                            
                        }



                        
?>
                        
                        <?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): ?>
" If I looks more intelligence please increase my reputation."
Reply
#20

I give up.
In your updatesettings method (2 posts ago), you only set $data['setting'] if validation succeeds.
Of course you will get an undefined variable error message if you load the settings view if validation fails.
I am out of patience and time to help you learn the basics of PHP programming.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB