Why is this warning occuring when I am using IE?
Warning: Invalid argument supplied for foreach()
It works in all other browsers..
The function for the loop:
function wdsearch(PDO $dbh){
if(!isset($_POST['wdsubmit'])) {
} else {
$term = $_POST['wdsearchvalue'];
$stmt = $dbh->prepare("
SELECT *
FROM posts
WHERE category = :designer
AND (full_text LIKE CONCAT('%', :term, '%')
OR heading LIKE CONCAT('%', :term, '%'))
ORDER BY post_date DESC
");
$designer = 'Designer';
$stmt->bindParam(":designer", $designer);
$stmt->bindParam(":term", $term);
$stmt->execute();
return $stmt->fetchAll();
}
}
wdsearch($dbh);
$wdsearch = wdsearch($dbh);
And the loop goes here..
<?php foreach($wdsearch as $wds) : ?>
<!-- HTML here -->
<?php endforeach; ?>
Any possible IE related warnings? Like I said all other browsers can handle it..
The specified error is occurring in your PHP code, not in any specific browser.
The issue is, the datatype of
$wdsearch, does not implement aniterator. This could be caused by$wdsearchbeingnull, a string/number/etc. – or simply an unsupporting object.Try verifying if the data is an array before going into the
foreachloop withis_array($wdsearch), or verify the variable is not null withisset($wdsearch). If you believe there is valid data there, check to see if the object in$wdsearchactually supports iterators and, if not, update it to implement!Example: