Jump to content

[SOLVED] Why am I getting a "Notice: Undefined variable"


jamcoupe

Recommended Posts

It say:

Notice: Undefined variable: articledata in /Applications/MAMP/htdocs/jstar/news.php on line 22

On the normal news.php page but not when I have news.php?article=1

 

Does anyone know how to solve it. Heres my code.

<?php
//gets information to display the article on its own page.
if(isset($_GET['article'])) {
	$query = "SELECT * FROM news WHERE id={$_GET['article']} ";
	$get_article = mysql_query($query, $connect);
	if(!$get_article) {
		die("Database Query Failed: ".mysql_error());
	}
		if ($articledata = mysql_fetch_array($get_article)) {
	} else {
		$articledata = NULL;
	}
}


?>
<?php include("includes/header.php"); ?>
<?php 
//****Line 22 below****//
if (!is_null($articledata)) {
?>
        <div class="news">
        <h3 class="news_title"><?php echo $articledata["title"] ?></h3>
        <p class="news_content"><?php echo $articledata["content"]; ?></p>
        <p class="news_bottom">[<?php echo $articledata["date"];?>]<br />by jamcoupe</p>
        </div>
        <a href="news.php">Back</a>
<?php
} else {
	$get_news = get_news();
	?>
	<h2>News</h2>
        <p><a href="addnews.php">Add News</a></p>
	<?php
	while ($articledata = mysql_fetch_array($get_news)) {
?>
	<div class="news">
	<h3 class="news_title"><a href="news.php?article=<?php echo $articledata['id']; ?>"> <?php echo htmlentities($articledata['title']); ?></a></h3>
	<p class="news_content"><?php echo strip_tags(nl2br($articledata['content']), "<br>"); ?></p>
	<p class="news_bottom">[<?php echo $articledata['date'];?>]<br />by jamcoupe<br /><a href="editnews.php?article=<?php echo $articledata['id']; ?>">[Edit]</a> <a href="deletenews.php?article=<?php echo $articledata['id']; ?>" onclick="return confirm('Are you sure you want to delete: <?php echo $articledata['title']; ?>?');">[Delete]</a></p>
	</div><br />	

<?php
}
}
?>

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.