I think he will get:
Invalid News Item
Sorry, you failed to specify a valid article.
| SitePoint Sponsor |
I think he will get:
Invalid News Item
Sorry, you failed to specify a valid article.

unfortunately the same thing i get the list of clickable titles (click them and its a dead link even though they have the correct id) and before clicking anything "Invalid News Item
Sorry, you failed to specify a valid article." shows.
thanks for your time and effort thus far
I think the block below will be executed:
else
{
echo '<h3>Invalid News Item</h3>';
echo '<p>Sorry, you failed to specify a valid article.</p>';
}
there is no value in $_GET variable, this is why the if condition is not becoming true.
Can you post the link you clicked which led you to this error? As Salahsoft stated, it appears the id is not populated, or populated incorrectly.
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

The invalid error shows upon loading the page, nothing is clicked. If a title is clicked then it takes u to a broken link (i have checked the id's and they are correct and populated). Not sure what you mean when you say post the link but anything else i can tell you to help let me know.
thanks again
We are asking you to post the link on which titles appear. We will check it.
A broken link?
You do have 2 separate scripts at work here don't you? One to display the links, and another to display the article?
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

i do but they are within the same page as mentioned earlier?
Salah - the page is local
Ah ha,
The first bit of code sends the user to another script to display the article, hence you're receiving a 404.
You need to re-code the logic for this, all the elements are there, you just need to re-jig them.
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
I can try to resolve if you upload it to an online webhost.

Hmm, so does that mean it would work if i put the display code into a different page (which is perfectly usable)? I just dont understand how it would know what page to send you to if this was the case..
Here, place this script on the root of your server and call it newsSample.php.
PHP Code:<?php
/*
Include connection details here!
*/
if(isset($_GET['newsid']) && !empty($_GET['newsid']) && ctype_digit($_GET['newsid']))
{
$sSQL = sprintf("SELECT title, content FROM news WHERE id = %s",
$_GET['newsid']
);
$rResult = mysql_query($sSQL);
if(!is_resource($rResult))
{
echo '<h3>System Error</h3>';
echo '<p>' . mysql_error() . '</p>';
echo '<p><a href="/newsSample.php">Return back to archive</a>.</p>';
exit;
}
if(mysql_num_rows($rResult) === 1)
{
$aNewsItem = mysql_fetch_assoc($rResult);
printf('<h3>%s</h3><p>%s</p>',
htmlentities($aNewsItem['title']),
htmlentities($aNewsItem['content'])
);
echo '<p><a href="/newsSample.php">Return back to archive</a>.</p>';
}
else
{
echo '<h3>Invalid News Item</h3>';
echo '<p>Sorry, no article could be found matching your request.</p>';
echo '<p><a href="/newsSample.php">Return back to archive</a>.</p>';
}
}
else
{
$sSQL = 'SELECT id, title FROM news';
$rResult = mysql_query($sSQL);
while ($aNewsItem = mysql_fetch_assoc($rResult))
{
printf('<a href="/newsSample.php?newsid=%s" title="%s">%s</a><br />',
$aNewsItem['id'],
htmlentities($aNewsItem['title']),
htmlentities($aNewsItem['title'])
);
}
}
?>
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
You may put the display code into separate file, however, if it already contains the error i.e. $_GET variable empty, then you will again get error.

Silver just to confirm what i need to do, use the above code and save it as newsSample.php - place it in root. Then it should all work together or i need to call it (via include) in the page that contains the title links?
Try it stand alone, we'll discuss the rest later.![]()
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

Your going to get sick of this code lol!
right so i went to local/newsSample.php and get a blank page besides the titles of the news articles, click them and once again a dead link...
if possible try it stand alone on online hosting.

tried - same problem
can you test each line using die() statement as mentioned by Salahsoft

I can but would that not result in the same as what happened when we tried that earlier?
you should go line by line, this will make you find issues.
Bookmarks