prezident Posted January 1, 2011 Share Posted January 1, 2011 if(!is_array($e)) { $fulldisp = 1; $e = array('title' => 'No Entries Yet', 'entry' => '<a href="../admin.php">Post an entry!</a>' ); } } // Add the $fulldisp flag to the end of the array array_push($e, $fulldisp); return $e; } can someone please tell me why I'm getting this notice ? Notice: Undefined variable: e in /var/www/blog/inc/functions.inc.php on line 40 Quote Link to comment Share on other sites More sharing options...
sooner Posted January 1, 2011 Share Posted January 1, 2011 is the $e is declared before checking is_array($e)...that might be the error... Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted January 1, 2011 Share Posted January 1, 2011 post complete function here... Quote Link to comment Share on other sites More sharing options...
prezident Posted January 1, 2011 Author Share Posted January 1, 2011 <?php function retrieveEntries($db, $id=NULL){ if(isset($id)) { $sql = "SELECT title, entry FROM entries WHERE id=? LIMIT 1"; $stmt = $db->prepare($sql); $stmt->execute(array($_GET['id'])); $e = $stmt -> fetch(); $fulldisp = 1; } else { $sql = "SELECT id, title FROM entries ORDER BY created DESC"; foreach($db->query($sql) as $row){ $e[] = array('id' => $row['id'], 'title' => $row['title'] ); } $fulldisp = 0; if(!is_array($e)) { $fulldisp = 1; $e = array('title' => 'No Entries Yet', 'entry' => '<a href="./admin.php">Post an entry!</a>' ); } } array_push($e, $fulldisp); return $e; } function sanitizeData($data){ if(!is_array($data)) { return strip_tags($data, "<a>"); } else{ return array_map('sanitizeData', $data); } } ?> Here is the whole function.. Quote Link to comment Share on other sites More sharing options...
prezident Posted January 1, 2011 Author Share Posted January 1, 2011 Maybe it's the database not saving my entry to the array because when i click save my entries don't save here is the update code... <?php //if the full display flag is set, show the entry if($fulldisp==1) { ?> <h2> <?php echo $e['title'] ?> </h2> <p> <?php echo $e['entry'] ?> </p> <p class="backlink"><a href="./">Back to Latest Entries</a> </p> <?php } //end the if statement //if the full display flag is 0, format linked entry title else{ //loop through each entry foreach($e as $entry){ ?> <p> <a href="?id=<?php echo $entry['id'] ?>"> <?php echo $entry['title'] ?> </a> </p> <?php } //end the foreach loop } //end the else ?> <p class="backlink"><a href="/admin.php">Post a New Entry</a> </p> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
BLaZuRE Posted January 1, 2011 Share Posted January 1, 2011 You need to correctly tab your code so your opening and closing brackets align. You'll probably see your error that way. I think: array_push($e, $fulldisp); may be the problem. It's outside the if,then section, meaning it is not checked whether it is an array or not. Can you tell us which is line 40, the line it errors on? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.