comment page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

comment page

Post by robjime »

I made this comment page. It works well but theres only one problem. When you submit a comment it goes into the database fine but it doesn't show up until you refresh the page. But when you refresh the page it adds the same comment to the database again. Is there a way around that?
Heres the code:

Code: Select all

<?php 
//this part gets the entry someone is commenting on
		  include('config.inc.php');
		  $id = $_GET['p'];
		  mysql_connect($dblocal, $dbuser, $dbpassword);
		  mysql_select_db($database);		
		  $query = "Select * From rr_posts WHERE id='$id'";
		  $result1 = mysql_query($query);
		  $post = mysql_fetch_array($result1);
		  echo '<font color="';
	echo $datec;
	echo '"';
	echo 'size="4.5" face="';
	echo $datef;
	echo '">';
	echo '<strong>';
	echo $post['date'];
	echo '</strong></font> <br>';
    echo '<hr align="center" noshade>';
    echo '<font color="';
	echo $titlec;
	echo '"'; 
	echo 'face="';
	echo $titlef;
	echo '">';
	echo $post['title'];
	echo '</font><br><em><font color="';
	echo $catc;
	echo '"';
	echo 'size="2" face="';
	echo $catf;
	echo '">';
	echo 'Catagory:';
	echo '<a href="http://www.robsreport.com/index.php?cat=';
	echo $post['cat'];
	echo '">';
	echo $post['cat'];
	echo '</a>';
	echo '</font></em><br><br><font color="';
	echo $contentc;
	echo '"';
	echo 'face="';
	echo $contentf;
	echo '">';
	echo $post['content'];
	echo '</font>';
	echo '<br>';
	echo '<br>';
	?>
          <font size="4" face="Batang"><strong>Comments:</strong></font> 
          <hr align="center" size="1" noshade>
          <?php
//this is where the comments show up and get posted
$query2 = "Select * From rr_comments WHERE post_id='$id'";
$result2 = mysql_query($query2);
$r2ar = mysql_num_rows($result2);
if($r2ar == 0) {
echo 'No comments yet.';
}
else {
$i = 0;
while ($i < $r2ar) {
$author = mysql_result($result2, $i, 'author');
$email = mysql_result($result2, $i, 'email');
$homepage = mysql_result($result2, $i, 'homepage');
$comment = mysql_result($result2, $i, 'comment');
echo $comment;
echo '<br>';
echo'<font face="Georgia, Times New Roman, Times, serif" size=2><em>Posted by:';

echo '<a href="';
echo $homepage;
echo '">';
echo $author;
echo '</a>';
echo '</font></em>';
echo '<br>';

$i ++;

}
}
		  if(isset($_POST['commentgo'])) {
		  $name = $_POST['name'];
		  $email = $_POST['email'];
		  $homepage = $_POST['homepage'];
		  $comment = $_POST['comment'];
		  $query3 = "INSERT INTO rr_comments VALUES ('','$id','$name','$email','$homepage','$comment')";
		  $result3 = mysql_query($query3);
		  }
		  
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

put the insertion before the comment search query
robjime
Forum Commoner
Posts: 46
Joined: Sat Apr 03, 2004 12:26 pm
Location: the RO

Post by robjime »

so im guessing php reads from top to bottom?
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post by genetix »

robjime wrote:so im guessing php reads from top to bottom?
yes
Post Reply