jamcoupe Posted August 10, 2009 Share Posted August 10, 2009 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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169654-solved-why-am-i-getting-a-notice-undefined-variable/ Share on other sites More sharing options...
taquitosensei Posted August 10, 2009 Share Posted August 10, 2009 put $articledata=NULL; just before the query you can also then remove the else Quote Link to comment https://forums.phpfreaks.com/topic/169654-solved-why-am-i-getting-a-notice-undefined-variable/#findComment-895006 Share on other sites More sharing options...
jamcoupe Posted August 10, 2009 Author Share Posted August 10, 2009 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/169654-solved-why-am-i-getting-a-notice-undefined-variable/#findComment-895007 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.