SitePoint Sponsor |
|
User Tag List
Results 26 to 47 of 47
Thread: Link to website from query
-
Feb 18, 2009, 05:54 #26
I think he will get:
Invalid News Item
Sorry, you failed to specify a valid article.
-
Feb 18, 2009, 06:05 #27
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Feb 18, 2009, 06:05 #28
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>';
}
-
Feb 18, 2009, 06:07 #29
there is no value in $_GET variable, this is why the if condition is not becoming true.
-
Feb 18, 2009, 06:09 #30
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Feb 18, 2009, 06:14 #31
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Feb 18, 2009, 06:15 #32
We are asking you to post the link on which titles appear. We will check it.
-
Feb 18, 2009, 06:16 #33
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Feb 18, 2009, 06:19 #34
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i do but they are within the same page as mentioned earlier?
Salah - the page is local
-
Feb 18, 2009, 06:22 #35
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Feb 18, 2009, 06:24 #36
I can try to resolve if you upload it to an online webhost.
-
Feb 18, 2009, 06:27 #37
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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..
-
Feb 18, 2009, 06:31 #38
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Feb 18, 2009, 06:32 #39
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.
-
Feb 18, 2009, 06:38 #40
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?
-
Feb 18, 2009, 06:42 #41
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Feb 18, 2009, 06:49 #42
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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...
-
Feb 18, 2009, 06:49 #43
if possible try it stand alone on online hosting.
-
Feb 18, 2009, 06:52 #44
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
tried - same problem
-
Feb 18, 2009, 06:56 #45
can you test each line using die() statement as mentioned by Salahsoft
-
Feb 18, 2009, 15:47 #46
- Join Date
- Nov 2008
- Posts
- 140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I can but would that not result in the same as what happened when we tried that earlier?
-
Feb 19, 2009, 21:16 #47
you should go line by line, this will make you find issues.
Bookmarks