The script below (list.php) retrieves data from a database to list article titles. By clicking the hyperlink, the article text is supposed to appear when accessing story.php based on the $id variable passed through to the file "story.php". However I get this error msg when loading story.php.:
"Notice: Undefined variable: id in c:\easyphp\www\story.php on line 12."
Address line shows: http://localhost/story.php?id=1
It does not recognize the id variable, why ?
Please help. This script has worked before. However, I have recently installed php version 4."something" on my computer and run Apache.
Thanks for any help.
list.php:
<?
include("conf.php");
//include("functions.php");
$connection = mysql_connect($host,$user,$pass) or die ("db feil");
mysql_select_db($db) or die ("Uanble to select database");
$query = "SELECT id, slug, timestamp FROM news ORDER BY timestamp DESC LIMIT 0,5";
$result = mysql_query($query) or die ("Error in query");
// if records present
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_object($result))
{
?>
<li><font size="-1"><b><a href="story.php?id=<? echo $row->id; ?>"><? echo $row->slug; ?></a></b></font>
<br>
<font size="-2"> <? echo $row->timestamp; ?></font>
<p>
<?
}
}
// if no records present
else
{
?>
<font size="-1"> No press releases currently available </font>
<?
}
// close database connection
mysql_close($connection);
?>
story.php
<?
include("conf.php");
include("functions.php");
$connection = mysql_connect($host,$user,$pass) or die ("db feil");
mysql_select_db($db) or die ("Uanble to select database");
$query = "SELECT slug, content, contact, timestamp FROM news WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query");
$row = mysql_fetch_object($result);
// print details
if($row)
{
?>
<p>
<b><? echo $row->slug; ?></b>
<p>
<font size="-1"><? echo nl2br($row->content); ?></font>
<p>
<font size="-2">This press release was published on <? echo $row->timestamp; ?>.
For more information, please contact <? echo $row->contact; ?></font>
<?
}
else
{
?>
<p>
<font size="-1">That press relase could not be located. </font>
<?
}
// close database connection
mysql_close($connection);
?>