Update has been successful. Setting has been successfully updated!
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/settings.php

Line Number: 68

Backtrace:

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\companygiondaci\application\views\settings.php
Line: 68
Function: _error_handler

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\companygiondaci\application\controllers\Cpages.php
Line: 683
Function: view

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\companygiondaci\index.php
Line: 315
Function: require_once

Line 68: <?php foreach($setting as $setting_item): ?>

views/settings.php

<?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($query->result() as $setting_item): ?>
                        <?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 ?>

Dani AI

Generated

PHP's "Invalid argument supplied for foreach()" means the variable handed to foreach is not iterable (not an array or Traversable object). In the supplied view the same name appears to be used both as a success flag and as the settings data, so when the update path returns a boolean the template later tries to iterate that boolean — which triggers the warning. Reusing one variable for two different types is the most likely root cause.

Recommended corrections and safe-guards:

  • Keep data and flags separate. Have the controller pass the settings collection (e.g. $settings) and a distinct boolean or flash message (e.g. $update_success). Prefer redirect + flashdata after a successful update so the view always receives a consistent settings object.
  • Defensively check the variable before looping. For example:
if (is_array($settings) || $settings instanceof Traversable) {
  foreach ($settings as $item) {
    // render fields
  }
} else {
  // render empty/default form or a friendly message
}
  • If the settings come from a single DB row, avoid foreach entirely and use the single-row result (access fields directly).

Troubleshooting checklist (as suggested inspecting the controller): confirm what the controller assigns to the view, verify the model methods' return types (boolean on update vs. array/object on fetch), and log the variable type/value (var_export or error_log) before the view loads. Correct variable naming and a simple type check will remove the warning and make behavior predictable.

Can you show the method controller?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.