 <p>This is happening because in HTML you have multiple textareas with same <code>id</code> attribute that is <code>txtcomment</code>. You should try giving each textarea, comments anchor tag a unique id.</p> <p>use <code>id="txtComment.'.$row["id"].'"</code> and <code>id="leavecomment.'.$row["id"].'"</code></p> <blockquote> <p>NOTE: when an HTML page have multiple DOM element with same <code>id</code>, it will traverse through the last one and return the last occurrence of element.</p> </blockquote>