Page 1 of 1

Coding error ?

Posted: Wed Apr 07, 2010 10:52 am
by JackBe
Hi

I get the following error message on posting:

Warning: Invalid argument supplied for foreach() in /home/alpusol/public_html/auth/output_fns.php on line 536

Warning: Invalid argument supplied for foreach() in /home/alpusol/public_html/auth/db_fns.php on line 78

Warning: Invalid argument supplied for foreach() in /home/alpusol/public_html/auth/db_fns.php on line 78

Warning: Invalid argument supplied for foreach() in /home/alpusol/public_html/auth/output_fns.php on line 558


These are the relevant codes for each line ABOVE - in order;


foreach ($img_array as $row) {$ref = stripslashes($row['ref']); $img = stripslashes($row['img']); }

foreach ($array as $row) $counter = $counter+1;return $counter;}

foreach ($array as $row) $counter = $counter+1;return $counter;}

foreach ($img_array as $row) {
$ref = stripslashes($row['ref']);
$img = stripslashes($row['img']);
$esp = stripslashes($row['descrip_esp']);
$engl = stripslashes($row['descrip_engl']);
$alem = stripslashes($row['descrip_alem']);

Can anyone see any obvious error that I have made in the code?

The PHP is version 5.2.8

Many thanks

Jack

Re: Coding error ?

Posted: Wed Apr 07, 2010 12:06 pm
by requinix
What's the rest of the file?

Re: Coding error ?

Posted: Wed Apr 07, 2010 12:44 pm
by jbulaswad
JackBe,

Those are PHP warnings (versus errors) letting you know that the arrays you are attempting to loop through are not arrays or are empty arrays/variables.

To solve this you can adjust the error logging level by placing error_reporting(E_ERROR); at the head of your script (See http://us.php.net/manual/en/function.er ... orting.php) or you may check the array by using the following if statement if (count($row)) { } (See http://us.php.net/manual/en/function.count.php).

Re: Coding error ?

Posted: Wed Apr 07, 2010 5:58 pm
by minorDemocritus
jbulaswad wrote:To solve this you can adjust the error logging level by placing error_reporting(E_ERROR); at the head of your script (See http://us.php.net/manual/en/function.er ... orting.php)
Per the Posting Guidelines, as well as common sense, "Telling someone to turn down their error reporting is not a valid solution."
JackBe wrote:

Code: Select all

foreach ($img_array as $row) {$ref = stripslashes($row['ref']);  $img = stripslashes($row['img']);    }

foreach ($array as $row) $counter = $counter+1;return $counter;}

foreach ($array as $row) $counter = $counter+1;return $counter;}

foreach ($img_array as $row) {
        $ref = stripslashes($row['ref']);
        $img = stripslashes($row['img']);
        $esp = stripslashes($row['descrip_esp']);
        $engl = stripslashes($row['descrip_engl']);
        $alem = stripslashes($row['descrip_alem']);
What are the contents of the $array and $img_array variables? Use var_dump() to investigate.

Re: Coding error ?

Posted: Wed Apr 07, 2010 6:24 pm
by minorDemocritus
JackBe wrote:

Code: Select all

foreach ($array as $row) $counter = $counter+1;return $counter;}

foreach ($array as $row) $counter = $counter+1;return $counter;}
Also... I don't really understand why you're using "return" here... if you're looping with FOREACH inside a function, don't you want all of the results?

Consider the following code:

Code: Select all

<?php
function returnLoop($inputArray) {
    foreach ($inputArray as $value) {
        return $value;
    }
}

$array = array(1, 2, 3);
$output = returnLoop($array);
var_dump($output);
?>
This will only output a single int, the value being 1.

Please use the [ syntax=php ] [ /syntax ] bbcode on code blocks, so it's syntax highlighted. It's much easier on the eyes that way.