Jump to content

happy new years function error...


prezident

Recommended Posts

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

Link to comment
Share on other sites

<?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..

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.