Comment form disappears after submit

Hi all,

This has me going around in circles so I’m hoping someone can shed some light on my problem.

I have a user profile page, on this page I have included a comments system via

require_once(‘comments.php’);

The problem I am having is that after entering and posting a comment the text field for entering the comment along with the submit button disappear. The actual comment does not show on the page.

Refreshing the page resubmits the comment so it now appears twice, but the actual form and the post button still do not show.

Any ideas? Here is the code for comments.php
[php]//query comments for this page of this article
$inf = “SELECT * FROM comments WHERE page = '”.stripslashes($_SERVER[‘REQUEST_URI’])."’ ORDER BY id DESC";
$info = mysql_query($inf);
if(!$info) die(mysql_error());

$info_rows = mysql_num_rows($info);
if($info_rows > 0) {
echo ‘’;
echo ‘

’;
?>
<? while($info2 = mysql_fetch_object($info)) { echo '
'; echo ''; echo ''; echo ''; echo ''; }//end while echo '
'.stripslashes($info2->subject).'From: '.stripslashes($info2->username).'
'.stripslashes($info2->comment).'
'; echo '
'; } else echo 'No notes for this page.
';

if(isset($_POST[‘submit’])) {
if(!addslashes($_POST[‘comment’])) die(‘ERROR: cannot add comment if you do not enter one!?’);
?>

<? //try to prevent multiple posts and flooding... $c = "SELECT * from `comments` WHERE ip = '".$_SERVER['REMOTE_ADDR']."'"; $c2 = mysql_query($c); while($c3 = mysql_fetch_object($c2)) { $difference = time() - $c3->time; if($difference < 300) die('ALERT: '.$c3->username.', You have already commented earlier; if you have a question, try the forums!
'); } //end while //add comment $username=$qls->user_info["username"]; $contact=($_POST["userprofiles.php?username=' . $qls->user_info['username'] . '"]); $q ="INSERT INTO `comments` (article_id, page, date, time, username,contact,comment) VALUES ('".$_GET['id']."', '".$_POST['page']."', '".$_POST['date']."', '".$_POST['time']."', '$username', '$contact', '".addslashes(htmlspecialchars(nl2br($_POST['comment'])))."')"; $q2 = mysql_query($q); if(!$q2) die(mysql_error()); } else { //display form ?>
 </div> 
">
<tr> 
  <td><div align="right"></div></td> 
  <td><textarea name="comment" cols="25" rows="3" wrap="VIRTUAL"></textarea></td> 
</tr> 
<tr>  
  <td></td>
    </table> 
	<div id="post">
     <input type="image" src="img/post.png" name="submit" value="Add Comment"> 
<? } // end else ?> [/php]

Solved it after checking the code for what must have been the 1000th time :-\

On line 65 I removed “else”, I’m new at .php but best I can tell I was telling the script to either add the comment or display the content… now it does both (yay!)

Sponsor our Newsletter | Privacy Policy | Terms of Service