PHP: Warning: array_push() expects parameter 1 to be array, boolean given?
-
I am reading 'PHP for absolute beginners' and I am stuck on page no. 183 , where it shows me 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 , when it is an array! here 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)); } ?> please help me out! thanks in advance!
-
Answer:
Since I cant run it to duplicate/debug, I will suggest you look at this: When you set $e here, $e = $stmt->fetch(); what value does $e have?
Aman Grover at Yahoo! Answers Visit the source
Related Q & A:
- how to estimate the phase parameter of a complex function?Best solution by Mathematics
- How can I prevent memory warning in IOS?Best solution by cultofmac.com
- How to pass javascript jQuery variable value in php array?Best solution by Stack Overflow
- How to post an array of complex objects (that has an array of complex objects) with jQuery?Best solution by Stack Overflow
- how can i remove an array from an array?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.