I am reading "PHP for absolute beginners" but I am stuck on page 183 where I get an error--
Warning: array_push() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\simple_blog\inc\function… on line 60
Warning: array_pop() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\simple_blog\index.php on line 27
and
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\simple_blog\index.php on line 68
I don't know why it is returning $e as a boolean and not an array!
I thought this is a great place to put up this question
below is the code for functions.inc.php file---
<?php
function retrieveEntries($db, $page, $url=NULL)
{
if(isset($url))
{
$sql = "SELECT id, page, title, entry
FROM entries
WHERE url=?
LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->execute(array($url));
$e = $stmt->fetch();
$fulldisp = 1;
}
else
{
$sql = "SELECT id, page, title, entry, url
FROM entries
WHERE page=?
ORDER BY created DESC";
$stmt = $db->prepare($sql);
$stmt->execute(array($page));
while($row = $stmt->fetch())
{
$e[] = $row;
$fulldisp = 0;
}
if(!is_array($e))
{
$fulldisp = 1;
$e = array(
'title' => 'No Entries Yet!',
'entry' => 'This Page Does Not Have An Entry Yet!!'
);
}
}
array_push($e , $fulldisp );
return $e;
}
function sanitizeData($data)
{
if(!is_array($data))
{
return strip_tags($data, "<a>");
}
else
{
return array_map('sanitizeData', $data);
}
}
function makeUrl($title)
{
$patterns = array(
'/\s+/',
'/(?!-)\W+/'
);
$replacements = array('-' , '');
return preg_replace($patterns , $replacements , strtolower($title));
}
?>