Hi everyone, i'm having a little problem with this file im currently coding. If the $_GET['story'] is used, show only the story they want, if they didnt select 1, show them all! Thats whats happening below... BUT I get an error...
Code:
Notice: Undefined index: story in c:\program files\easyphp1-8\www\news script\news.php on line 7
// Include the database connection
include("connect.php");
// Get the story variable
$story = $_GET['story'];
// Is the story variable sent?
if(isset($story)) {
// Select the item from the news which they wanna view
$result=mysql_query("SELECT * FROM news WHERE id = ".$story." LIMIT 1");
while($row=mysql_fetch_array($result)) {
// Pull information out
$id = $row['id'];
$author = $row['author'];
$title = $row['title'];
$content = $row['content'];
$date = $row['date'];
// Get rid of the dirty slashes
$date = stripslashes($date);
$author = stripslashes($author);
$title = stripslashes($title);
$content = stripslashes($content);
// Show the news which they selected
echo("$title - $date - $author");
}} else {
// Connect and show all the news
$result1=mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 5");
while($row=mysql_fetch_array($result1)) {
// Pull out the information
$id = $row['id'];
$author = $row['author'];
$title = $row['title'];
$content = $row['content'];
$date = $row['date'];
// Get rid of the dirty slashes
$date = stripslashes($date);
$author = stripslashes($author);
$title = stripslashes($title);
$content = stripslashes($content);
// Show it to them, including the link for just 1 story
echo("<a href=\"news.php?story=".$id."\">$title - $date - $author</a>");
}}
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life. Please login or register to view this content. Registration is FREE
PiterZ is correct - you're getting that notice because the $story variable isn't defined, so the script stops before it even gets to the if-statement. Thus, this means that the $_GET probably isn't being sent through and so the error may be routed slightly deeper.
__________________ A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill
Please visit my sites: Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE