Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Code:
[b]$post_id[/b] = $row['entry_id'];

and then


Code:
$entry = basename(__FILE__);
[b]$post_id[/b] = mysql_query("SELECT entry_id FROM blog_entries WHERE title = '$entry' LIMIT 1"); 
$row = mysql_fetch_assoc($post_id); 
[b]$post_id[/b] = $row['entry_id'];

is where you are re-using this variable name.

Resource ID#5 is ok, depending on what you echo, most likely the resource that you save the mysql_fetch_assoc to.
 
Alright I changed it to
Code:
$post_id = mysql_query("SELECT entry_id FROM blog_entries WHERE title = '$entry' LIMIT 1");  

$row = mysql_fetch_assoc($post_id); 
$post = $row['entry_id']; 
$query = mysql_query("SELECT * FROM `blog_comments` WHERE post_id='$post'");

Is that still valid? Its still a no go though.
 
Alright I changed it to
Code:
$post_id = mysql_query("SELECT entry_id FROM blog_entries WHERE title = '$entry' LIMIT 1");  

$row = mysql_fetch_assoc($post_id); 
$post = $row['entry_id']; 
$query = mysql_query("SELECT * FROM `blog_comments` WHERE post_id='$post'");

Is that still valid? Its still a no go though.

Try this and tell what happens:

HTML:
$post_id = mysql_query("SELECT entry_id FROM blog_entries WHERE title = '$entry' LIMIT 1");  

$row = mysql_fetch_assoc($post_id); 
$post = $row['entry_id']; 
echo "POST $post <br />";
$query = mysql_query("SELECT * FROM `blog_comments` WHERE post_id='$post'");
echo "QUERY $query <br />";

This will tell us whats is being passed if anything.
 
Alright I changed it to
Code:
$post_id = mysql_query("SELECT entry_id FROM blog_entries WHERE title = '$entry' LIMIT 1");  

$row = mysql_fetch_assoc($post_id); 
$post = $row['entry_id']; 
$query = mysql_query("SELECT * FROM `blog_comments` WHERE post_id='$post'");

Is that still valid? Its still a no go though.

Well, remember your code uses $post_id later on after this code so you would need to change all the following $post_id to $post, or make the formally first $post_id $post so there's less to change. Then also do what Cerebrus' Maw suggested using the fixed variable names.

Also remember that the data in the DB won't change on its own, you'll need to fix or remove that data because they'll keep that 0 on post_id unless you act on it.

Note: I won't be around much due to holidays. Good luck.
 
When I did what Cerebrus' Maw said I got the following output:

POST
QUERY Resource id #5

When I changed the post_id's manually in the DB, the comments didn't display at all.

I'll keep working on it! Happy Thanksgiving!! :D
 
Hey guys, I think I found one problem: I was looking up basename(__FILE__) and I think we were using it wrong. It gets the name of the current script, which was comment_display.php not the post. This could have contributed to out failures. So I copied the comment_display file into each of the posts, ran an echo and it got the right file name. I then re-ran Cerebrus' Maw's scripts and got the following:

POST
QUERY Resource id #4

So it went from 4 to 5, does that mean anything? It still doesn't work, all the posts still have a post_id of 0. I'm still working on it.

EDIT: I don't think the problem is not in comment_display, rather the problem is in comment_process.php (and possibly before *see below*) When I echo $entry, the value is nothing, or NULL. nothing shows up. So here's my theory:

Code:
	<div id="comments_wrap">
	<a name="comments">
	
<?php 
[COLOR="Blue"]//this used to be comment_display.php[/COLOR] 
mysql_connect ('localhost', 'root', 'root'); 
mysql_select_db ('Blog'); 
   
$entry = basename(__FILE__);
         
$post_id = mysql_query("SELECT entry_id FROM blog_entries WHERE title = '$entry' LIMIT 1");  
[COLOR="Red"][B]//when I echo post_id at this point, it doesn't display. That must mean that it is a NULL value. 
//that means that something's wrong with our query...I think[/B][/COLOR]
$row = mysql_fetch_assoc($post_id); 
$post = $row['entry_id']; 
$query = mysql_query("SELECT * FROM `blog_comments` WHERE post_id='$post'"); 
     
while($row = mysql_fetch_assoc($query)) { 
  $date = $row["month"].'.'.$row["day"].'.'.$row["year"];  
  $time = $row["hour"].':'.$row["minutes"]; 
   
     echo 
     ' <div id="comment_'.$row["id"].'" class="comment">
     <div class="details">'.$row["name"].'<br>'.$date.'<br>'.$time.'</div>
     <div class="v_line"></div>
     <div class="message">'.$row["comment"].'</div>
     </div>';
} 
?>
[COLOR="blue"]	//below this, in the hidden field in which we get entry's value, 
//is it possible that $post is not recognized because we have already closed php? 
//Does it know that it was used in the above script and remember its value? 
//If not, then everything would make sense. Does that make sense?[/COLOR]

		<form method="post" action="comment_process.php">
			<input type="hidden" name="entry" value="<?php echo [COLOR="Red"]$post[/COLOR]; ?>" />
		
			<label for="name">Name</label>
			<input type="text" name="name" value="" />
			
			<label for="website">Website</label>
			<input type="text" name="website" value="" />
			
			<label id="comment_label" for="comment">Comment</label>
			<div id="instructions">
			</div>
			
			<textarea rows="5" cols="10" name="comment"></textarea>
			
			
			<input id="submit" type="submit" name="submit" value="Submit" id="submit" />
			
			
		
		</form>
		
		
	

	</div>

I hope you understand what I'm saying. Is it possible that we need to make $post a global variable?
 
GUYS I GOT IT! I was looking through my code and I found a spelling error with one of my tables. I feel stupid. But the important part is: I GOT IT!! I can't thank you guys enough!! Now I just need to beef up security and get everything top-notch. Thanks so much!
 
GUYS I GOT IT! I was looking through my code and I found a spelling error with one of my tables. I feel stupid. But the important part is: I GOT IT!! I can't thank you guys enough!! Now I just need to beef up security and get everything top-notch. Thanks so much!

Cool beans. I was wondering if it might be an issue like that since the DB was the one thing you couldn't show us. Sorry for the mix-up on the __FILE__ variable. I don't generally use it much. One fix for this is to move the code line pertaining to this ($entry = basename(__FILE__); ) to inside each blog_post.php file, that way it references the right file. That's kind of a pain though.

An alternative for getting the current executing script is $_SERVER['PHP_SELF']. You'll want to make sure it outputs the right file.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.