CodeIgniter Forums
Edit Pages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Edit Pages (/showthread.php?tid=66040)

Pages: 1 2 3


Edit Pages - davy_yg - 08-27-2016

How to fix this error message?

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



Line 49: 

PHP Code:
<?php foreach ($pages as $pages_item): ?>


views/editpages.php


PHP Code:
<?php //$pages=array(); ?>
                    
                    <?php foreach ($pages as $pages_item): ?>
                    
                    <div class="widget-box">
                        <div class="widget-title"><h5>Pages</h5></div>
                        <div class="widget-content">
                        
                        <?php echo form_open('cpages/editpagesupdate'); ?>
                        <table border="0" style="width: 100%; height: 90px;">
                            <tr>
                                <td>Pages Name</td>
                                <td><input type="text" name="pages_name" value="<?php echo $pages_item['pages_name']; ?>"></td>
                            </td>
                            <tr>
                                <td>Create Date</td>
                                <td><input type="text" name="create_date" value="<?php echo $pages_item['create_date']; ?>"></td>
                            </td>    
                            <tr>
                                <td>Order</td>
                                <td><input type="text" name="pages_order" value="<?php echo $pages_item['pages_order']; ?>"></td>
                            </td>
                            <tr>
                                <td>View Content</td>
                                <td><textarea rows="3" cols="20" name="pages_content"><?php echo $pages_item['pages_content']; ?></textarea></td>
                            </td>
                            <tr>
                                <td></td>
                                <td><input type="submit" class="edit" name="submit" value="SUBMIT"></td>
                            </tr>
                        </table>            
                        </div>
                    </div>        

                    <?php endforeach; ?>
                    
                </div>
            </div> 



RE: Edit Pages - InsiteFX - 08-27-2016

When are you going to quit writing code and start to learn the languages and frameworks?


RE: Edit Pages - davy_yg - 08-27-2016

Sorry, I thought that is CI framework. And I know somethings about php - already 4 years with php. Eventhough some errors makes me question something?


RE: Edit Pages - ciadmin - 08-27-2016

Davy: the error message you are questioning is pure PHP ... "Invalid argument supplied for foreach()".
The $pages variable is either empty or undefined.
That should be apparent to someone with four years of PHP Sad


RE: Edit Pages - PaulD - 08-27-2016

Should be apparent with four weeks of php.


RE: Edit Pages - davy_yg - 08-27-2016

Lol. I think I am still new in this part and perhaps better on other part. I already read the manual and still do not understand it.

http://php.net/manual/en/control-structures.foreach.php

I try to activate this:

<?php $pages=array(); ?>

<?php foreach ($pages as $pages_item): ?>


RE: Edit Pages - davy_yg - 08-27-2016

This is the models:

models/Mpages.php


PHP Code:
public function update_pages($pages_id)
    {
        
        
$data = array(
            
'pages_name' => $this->input->post('pages_name'),
            
'create_date' => $this->input->post('create_date'),
            
'pages_order' => $this->input->post('pages_order'),
            
'pages_content' => $this->input->post('pages_content')
        );
    
        
$this->db->where('pages_id'$pages_id);
        return 
$this->db->update('pages'$data);
        
    } 



RE: Edit Pages - InsiteFX - 08-28-2016

Learn to program in PHP


RE: Edit Pages - davy_yg - 08-28-2016

I have read the tutorial. I only do not know how to fix this error message:


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



Line 49:

PHP Code:
<?php foreach ($pages as $pages_item): ?>


RE: Edit Pages - ciadmin - 08-28-2016

Davy: I repeat, the $pages variable is either empty or undefined.

The model snippet you provided earlier does not set $pages, as far as I can see.

In line 49 of your post above, where does $pages come from????????????
It is empty or undefined!!!!!!!!!!!!!