Page 1 of 1

comment page

Posted: Fri Dec 31, 2004 10:18 am
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);
		  }
		  
?>

Posted: Fri Dec 31, 2004 10:24 am
by feyd
put the insertion before the comment search query

Posted: Fri Dec 31, 2004 2:32 pm
by robjime
so im guessing php reads from top to bottom?

Posted: Fri Dec 31, 2004 6:35 pm
by genetix
robjime wrote:so im guessing php reads from top to bottom?
yes