Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That is because once you submitted the new comment it will acting as a form submit and it is not working as like AJAX.</p> <p>Easiest way is to use a separate php file to save comments and <a href="http://jquery.malsup.com/form/" rel="nofollow"><strong>jquery form</strong></a> plugin add this to <code>&lt;HEAD&gt;</code> tag in <strong>comment.php</strong></p> <pre><code>&lt;HEAD&gt; &lt;script src="http://malsup.github.com/jquery.form.js"&gt;&lt;/script&gt; &lt;script&gt; // wait for the DOM to be loaded $(document).ready(function() { // bind 'myForm' and provide a simple callback function $('#myForm').ajaxForm(function() { location.reload(); }); }); &lt;/script&gt; &lt;/HEAD&gt; &lt;?php $coms = mysql_query("select * from comments where id = '$id';",$db); if(!$coms) { echo "coms error ".mysql_error(); exit; } // debug if (mysql_num_rows($coms)&gt;0){ // 55 while($databack44 = mysql_fetch_array($coms)){ // 55 echo '&lt;div style="width:100%; float:left;"&gt;'.$databack44[comments].'&lt;/div&gt;'; } } // 55 else { echo 'No Comments'; } ?&gt; &lt;form method="post" action="function.php" id="myForm"&gt; &lt;textarea name="comments"&gt;&lt;/textarea&gt; &lt;input type="submit" value="Add" class="button green"&gt; &lt;input type="hidden" name="id" value="&lt;?=$id?&gt;"&gt; &lt;input type="hidden" name="additem" value="1"&gt; &lt;/form&gt; </code></pre> <p><strong>function.php</strong></p> <pre><code>if ($_POST[additem] == '1'){ // AA $additem = mysql_query(" insert into comments ( id, user_id, comments ) VALUES ( '$id', '$user', '$comments' )",$db); if(!$additem) { echo "input error ".mysql_error(); exit; } // debug } // close AA </code></pre> <p><strong>jquery form plugin</strong> is disabling the standard form submit function and send form data as ajax variables to the given <strong>form action url</strong>.</p> <p>after sending data to the <strong>function.php</strong>, <strong>comment.php</strong> will be reloading by location.reload().</p> <p>Now you have the new comments Hope this helps </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload