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
Coding error ?
Moderator: General Moderators
Re: Coding error ?
What's the rest of the file?
Re: Coding error ?
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).
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 ?
Per the Posting Guidelines, as well as common sense, "Telling someone to turn down their error reporting is not a valid solution."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)
What are the contents of the $array and $img_array variables? Use var_dump() to investigate.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']);
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 ?
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?JackBe wrote:Code: Select all
foreach ($array as $row) $counter = $counter+1;return $counter;} foreach ($array as $row) $counter = $counter+1;return $counter;}
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);
?>
Please use the [ syntax=php ] [ /syntax ] bbcode on code blocks, so it's syntax highlighted. It's much easier on the eyes that way.