Jump to content

PHP Function problem - article not found.


Hangwire

Recommended Posts

Hi everybody.

I'm using a very simple article script that displays news and so on where added.

It also has an admin panel of sorts, very simple, from where you actually post the articles.

I have this problem - The news show up on the front page just fine, but when I click the link to the article itself the server says that it cannot be found. I checked the database, checked the connections and everything. I also don't see the posting comment button show up, but everything is okay with the script and the database - perhaps a formatting problem?

 

Anyway, you can try THIS for yourself to see what I'm talking about.

 

Here is the code:

 

function DisplayComments(){

// For the database settings
include("settings.php");

// Then make the connection
Connect();

// To know what article we look at
$article = ($_GET['id']);

// To make every second row another color
    $count = 0;

// Fetch the results from database
$query = "SELECT * FROM comments WHERE article_id LIKE '$article' ORDER BY id DESC";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

// If there are any results, show them
if (!$numrows == ""){
while($row = mysql_fetch_array($result)){

$name = Secure($row['name']);
$website = Secure($row['website']);
$email = Secure($row['email']);
$comment = htmlentities($row['comment']);
$date = $row['date'];
$on = date('F j, Y', strtotime($row['date']));
$at = date('g:i a', strtotime($row['date']));

$color = ($count % 2) ? $color1 : $color2;
$border = ($count % 2) ? $border1 : $border2;

echo "<div class='comm' style='background:$color;border-top:1px solid $border;border-bottom:1px solid $border;'>";

if (!$website == ""){
echo "<span class='by'><a href=\"$website\">$name</a></span>";
}
else{
echo "<span class='by'>$name</span>";
}

echo"<br /><span class='time'>$on @ $at</span><p>";

echo BBCode($comment);
echo "</p></div>";
$count++;

}
}
// If there are no results
else{
echo "<p>There are no comments for this article yet.</p>";
}

mysql_close();

}

 

 

function CheckComments ($id){

// First include the settings file
include("settings.php");

// Then we make the connection
Connect();

// Now we do the counting
$result = mysql_query("SELECT COUNT(*) as count FROM comments WHERE article_id LIKE $id")
or die("Error fetching number in DB<br>".mysql_error());
$row = mysql_fetch_array($result);
$numofrows = $row['count'];
$total = ceil($numofrows / $archive);

// To display 'comment' if there are more then one
// Otherwhise display 'comments'
if ($numofrows == 1){
$comm = "Comment";
}
else{
$comm = "Comments";
}

// If there are any comments, output the number of comments
if (!$total == ""){
echo "$numofrows $comm";
}
// Otherwhise we output a 'no'
else{
echo "<br> No $comm";
}
}

 

That gives me an only an "Object not found".

 

Also, as I said, I don't know how to add the comment button to each article as it currently doesn't show.

Here is the comment form function:

 

<?php
// Runs the function the display only one article
DisplayOne();
?>
<h4>Comments:</h4>
<?php
// Runs the funtion to display the comments that belongs to the article displayed
DisplayComments();
?>
<?php
echo "<h5>Add Your Comment</h5>";
// Variable to know what article we are commenting on
$article_id = intval($_GET['id']);
// Includes the comment form
include("comments/form.php");
?>

 

 

I hope you can understand what I tried to say, as it's 4.40AM here and my brain isn't working very well.

Thank you in advance!  :shy:

Link to comment
Share on other sites

The error message you posted doesn't appear in this code.  All this code you gave us is for fetching an article's COMMENTS, not the article itself.

 

Look in your code for the error message you're seeing.  That will give you a place to start.

 

-Dan

Link to comment
Share on other sites

Indeed it was late.

 

This is the function for posting an article

 

<?php	

// Connect to database
include("../settings.php");

$conn = mysql_connect($server, $user, $pass);
if (!$conn) die ("Couldn't connect to the database");
mysql_select_db($db, $conn) or die (mysql_error());

// Data from the form
$article_id = ($_POST['article_id']);
$name = mysql_real_escape_string($_POST['name']);
$website = mysql_real_escape_string($_POST['website']);
$email = mysql_real_escape_string($_POST['email']);
    $comment = mysql_real_escape_string($_POST['comment']);
$date = date("Y-m-d h:i:s");
$ip = $_SERVER["REMOTE_ADDR"];

// Then we check if everything is filled out
if ($name == ""){
echo "<div style='margin:0 auto;width:200px;text-align:center;'>
<img src='../images/caution.gif' alt='caution' /><br />
<p>Please fill in your name!</p>
<p><a href='javascript: history.go(-1)' style='color:#f7941d;'>Click here</a> to go back..</p>
</div>";
}
elseif ($comment == ""){
echo "<div style='margin:0 auto;width:200px;text-align:center;'>
<img src='../images/caution.gif' alt='caution' /><br />
<p>You <b>have</b> to fill in the comment!</p>
<p><a href='javascript: history.go(-1)' style='color:#f7941d;'>Click here</a> to go back..</p>
</div>";
}
else{
$query = "INSERT INTO comments (article_id,name,website,email,comment,date,ip) VALUES ('$article_id','$name','$website','$email','$comment','$date','$ip')";
$result = mysql_query($query) or die ("Error = ".mysql_error()."");

header("location: ../includes/ok2.php");

}


mysql_close($conn);

 

And this is what I found for displaying the article.

function DisplayLatest(){

// Includes the settings file
include("settings.php");

// Connect to database
Connect();

// Fetch from database
$query = "SELECT * FROM articles ORDER BY id DESC LIMIT ".$limit ."";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

// If there are results, show them
if (!$numrows == ""){
while($row = mysql_fetch_array($result)){

$id = $row['id'];
$name = Secure($row['name']);
$title = Secure($row['title']);
$content = stripslashes($row['content']);
$date = $row['date'];
$ip = $row['ip'];
$on = date('F j, Y', strtotime($row['date']));
$at = date('g:i a', strtotime($row['date']));

echo "
<div class='article'>
<h2><a href=\"article.php?id=$id\" title=\"Read more about $title\">$title</a></h2>
<span class='author'>By: $name on $on @ $at</span><span class='comments'><a href='article.php?id=$id'>";
echo CheckComments($id);
echo "</a></span>
<div class='post'><p>";

echo $content;

echo "</p></div></div>";
}
}

 

 

Again, I'm receiving an "Object not found" error when it's clearly written in the database - thats the whole issue.

Link to comment
Share on other sites

1)  We're programmers, not farmers.  Don't bump at 7am.

 

2)  That error STILL doesn't appear in the code you're giving us.  What, exactly, is giving you that error?  Is it on the screen?  In a modal dialog?  In a log file?  What, exactly, is the actual error?  Are you honestly just seeing "object not found" show up by itself with no other information somewhere?

 

3)  Don't include a file within a function, it's bad form and imports a bunch of unnecessary variables into a local scope that will just be destroyed.

 

-Dan

Link to comment
Share on other sites

It's an apache error! That's the whole point! How can a php script output an "Object not found!" error from apache?!

 

And, to Dan:

 

1) You know, there is more than 1 timezone on this planet.

2) Have you ever worked with apache, or do I need to be dead specific about everything?

3) Thank you.

Link to comment
Share on other sites

there should be a rule that if you don't understand that "Object not found" is now and will always be an apache error and only an apache error, regardless of how you configure apache or what kind of error strings you may have in your PHP code, you should not join this forum. silly us!

Link to comment
Share on other sites

Not at all what I had in mind.  :)

I expect to see a reply in a good tone, just as I always refer to anybody else on this site. But when somebody is condescending... People should know more than just scripting languages.  ::)

 

Let's go back on topic, though. Any ideas?  :rtfm:

Link to comment
Share on other sites

1)  Don't bump AT ALL, it's against the rules.  Especially don't bump when it's before breakfast time in the United States.

 

2)  You're purposefully not giving us all the information in order to...what?  Is this some kind of test where whoever figures out that you're randomly paraphrasing basic apache error messages becomes the next Highlander?  Give the error next time and we won't have to BEG you for enough information to fix your problem.  None of us assumed that you were getting a 404 message.  Do you know why?  Because you said "PHP is giving me <this error>" and then you pasted a bunch of unrelated PHP code.  Apache is giving you a 404.  You knew this the whole time, yet you posted in the PHP forum and included snippets of random PHP code. 

 

Yes, this turns out to be an apache error.  It took you 12 posts to actually say that, and now this is in the apache section.  However, this is a very easy error.  The file isn't where you think it is.  Move the file, or change your URL, and then you'll get to see all your PHP errors.  PHP isn't being hit because apache cannot find the object.  The object, in this instance, is the page you're trying to actually run. 

 

-Dan

Link to comment
Share on other sites

1) Wont bump, but there's another rule - All users must be courteous to others.  ;)

2) As I said in the first post, it was actually very late so... excuse me, in every post after the first one I presumed I had already mentioned it was concerning apache - didn't do that, but I gave an actual link, so it should have been pretty obvious.

 

Either way, my mistake.

 

Thank you so much for your help, I edited the directory and it's working like a charm!

All the best!  ;D

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.