Invalid argument supplied for foreach()
Posted: Sun Oct 26, 2008 9:15 pm
Ok so here is my deal. I have two class's, globalController and pagesController. globalController holds random snippets of code that i would like to reuse around the site, and pagesController is for the "pages" section of my app. when i call a foreach loop it gives me the invalid argument warning. here is my pagesController function:
the $g->all data() is the problem function ($g->alert_success() works fine for some reason) and here is its code from global controller:
the loop works fine if it's right in the update function but gives the error when i call it from the globalController class.
Suggestions? help? Thanks!
Code: Select all
function update(){
require 'globalController.php';
$g = new globalController();
//Grabs the page id from the url
$id = $_GET['id'];
//Saves the changes to the database
if(isset($_POST['content'])):
foreach($_POST as $var => $value):
$$var = $value;
$$var = str_replace( "'", "'", $$var);
endforeach;
mysql_query("UPDATE ida_pages SET
title='$title',
content='$content'
WHERE entryID = '$id'") or die(mysql_error());
$g->alert_success();
endif;
//Set's the mysql Query
$mysql = mysql_query("SELECT * FROM ida_pages WHERE entryID = '$id'");
$data = mysql_fetch_assoc($mysql);
//Set's all $data value's as var's
$g->all_data();
//Loads the Tinymce Scripts
print '<script type="text/javascript" src="../lib/tiny_mce/tiny_mce_gzip.js"></script>';
print '<script type="text/javascript" src="../lib/tiny_mce/pagesScript.js"></script>';
//The Form
print '<form action="'.$PHP_SELF.'" method="post">';
print '<button type="submit" class="save" title="Save"> </button>';
print '<a href="./" title="Back" class="back"> </a>';
print '<input type="text" name="title" value="'.$title.'" />';
print '<textarea name="content">'.$content.'</textarea>';
print '</form>';
}Code: Select all
//Set's all $data value's as var's
function all_data(){
foreach($data as $var => $value):
$$var = $value;
endforeach;
}Suggestions? help? Thanks!