Coding error ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JackBe
Forum Newbie
Posts: 1
Joined: Wed Apr 07, 2010 7:53 am

Coding error ?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Coding error ?

Post by requinix »

What's the rest of the file?
jbulaswad
Forum Newbie
Posts: 14
Joined: Tue Mar 30, 2010 2:37 pm
Location: Detroit, Michigan, USA

Re: Coding error ?

Post 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).
minorDemocritus
Forum Commoner
Posts: 96
Joined: Thu Apr 01, 2010 7:28 pm
Location: Chicagoland, IL, USA

Re: Coding error ?

Post 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.
Last edited by minorDemocritus on Wed Apr 07, 2010 6:25 pm, edited 1 time in total.
minorDemocritus
Forum Commoner
Posts: 96
Joined: Thu Apr 01, 2010 7:28 pm
Location: Chicagoland, IL, USA

Re: Coding error ?

Post 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.
Post Reply