Foreach invalid argument

Yeah I was just wondering what may have caused this. I downloaded all my files from my webhoster into a new folder so I could debug an error I was getting - thing is, the script works fine on my computer (localhost) - so I’m guessing it must be a server configuration problem?

This is the error:

Warning: Invalid argument supplied for foreach() in /home/~usr/public_html/  on line 17

Warning: Invalid argument supplied for foreach() in /home/~usr/public_html/  on line 834

Now line 17 of the first file is:

foreach($billing_cycle as $billing){
        echo insert_misc_options($host_id, $billing_table, $billing_field, $billing);
        delete_misc_options($host_id, $billing_table, $billing_field, $billing_cycle);

And the function producing the second error is:

function delete_misc_options($host_id, $table, $field, $opt) {
                    global $db;

                    $query =   "DELETE ";
                    $query .=  "FROM $table ";
                    $query .=  "WHERE ";

line 834 —> foreach($opt as $option) {
$query .= " $table.$field NOT LIKE $option";
$query .= " AND ";

                    $query .=  "$table.host_id = $host_id";

                    $result = mysql_query($query, $db);


And as I said - it works fine offline so I'm a little confused :confused:

Hosting PHP version: 5.2.9
Hosting MYSQL Version: 5
Hosting Apache: 2.2

My PHP Version: 5.2.13
My Apache 2.2

All the data and tables in the databases are the exact same, and none of the arrays being passed through the foreach are empty (which would understandably break the code) but as I said - files, database etc. exactly the same both on and offline.

Any help appreciated!

You need to do some debugging to see what you actually have, instead of what you think you have.

function delete_misc_options($host_id, $table, $field, $opt) { 
    global $db; 
    var_dump($opt); //HERE
    //build $query

    echo $query;  //HERE

And in your other block of code


Hmmm I used print_r to check the contents of my array before invoking any functions, and on my local machine the array shows the correct $_POST contents - but on my actual server hosting the array is empty, so it isn’t posting my form correctly. Thanks for the reply!

Any ideas?