i'm workin on an app that will allow a client to update news items themselves without needing to ftp or know sql. Just in the process of setting it all up, i've got a page that retrieves the title of the news item(referred to as a slug in this context), the date it was last updated and an id for the item. the title itself becomes a link to a page that contains the full content of the item by appending the id to the url and calling that id from the database. The first page (news.php) works fine, it retrieves what it needs to and sends the user to the next page (story.php) when they click the link.
However, for some reason the exception ("That press release could not be located in our database") is being displayed each time and not the content of the news story. i'm stumpted as to why this is the case as the fact that news.php is working shows there is data in there and that my connection script (db.php) is working.
These are the two scripts:
NEWS.PHP
<?php
require ('functions.php');
include 'db.php';
$pagename = 'News Page';
pagetop($pagename);
echo '
<h4>News Page</h4>
';
$query = "SELECT id, slug, timestamp FROM news ORDER BY timestamp DESC LIMIT 0, 5";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
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 formatDate($row->timestamp); ?></font>
<p>
<?
}
}
// if no records present
// display message
else
{
echo '<font size="-1">No press releases currently available</font>';
}
pagebottom();
?>
STORY.PHP
<?php
require ('functions.php');
include 'db.php';
$pagename = 'Full News Story';
pagetop($pagename);
$query = "SELECT slug, content, contact, timestamp FROM news WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// get resultset as object
$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 formatDate($row->timestamp); ?>. For more information, please contact <? echo $row->contact; ?></font>
<?
}
else
{
echo '
<p>
<font size="-1">That press release could not be located in our database.</font>';
}
pagebottom();
?>
Thanks.