I have here a posting system in which a person clicks on " | Comment " And then a div appears which has the following code in it .
<div class="commentbox" id="commentbox<?php echo $_row["id"];?>" style="display:none;"><div style="padding-right:10px;" align="right"><a class="close" href="#" id="<?php echo $_row['id'];?>">X</a></div>
<div class="scroll-pane">
<?php include 'load_comments.php';?>
</div>
<div class="commentupdate" id='commentbox<?php echo $_row["id"];?>'>
<div class="stcommenttext" >
<form method="post" action="">
<textarea name="comment" class="comment" maxlength="200" id="ctextarea<?php echo $_row["id"];?>"></textarea>
<br />
<input type="submit" value=" Comment " id="<?php echo $_row["id"];?>" class="comment_button button"/>
</form>
</div>
</div>
</div>
$_row['id']
is an sql fetch array
Load_comments.php
<?php
$commentquery = mysql_query("SELECT * FROM comments WHERE msgid=".$_row['id']."");
$count=mysql_num_rows($commentquery);
if($count!==0)
{
while($commrow = mysql_fetch_array($commentquery))
{
?>
<div class="stcommentbody" id="stcommentbody<?php echo $commrow['msgid']; ?>">
<div class="stcommentimg">
<?php $userdata = mysql_query('SELECT firstname,lastname,Photo FROM users WHERE id="'.$commrow["uic"].'"' );
$userrow = mysql_fetch_array($userdata); ?>
<img src="profile/<?php echo $userrow['Photo']; ?>" class='small_face' alt='<?php echo $userrow['firstname']; echo' ';echo $userrow['lastname']; ?>'/>
</div>
<div class="stcommenttext">
<?php if($commrow['uic']==$uid) { ?>
<a class="stcommentdelete" href="#" id='<?php echo $commrow['msgid']; ?>' title='Delete Comment'></a>
<?php } ?>
<b><a href="profile.php?id=<?php echo $commrow['uic']; ?>"><?php echo $userrow['firstname']; echo' ';echo $userrow['lastname']; ?></a></b> <?php echo $commrow['comment'];?>
<div class="stcommenttime"></div>
</div>
</div>
<?PHP
}
}else{
echo 'Be the first to comment';
}
?>
Now , On clicking the submit button , The following ajax is called in ,
<script>
$(document).ready(function() {
//Commment Submit
$('.comment_button').on("click",function(){
var ID = $(this).attr("id");
var comment= $("#ctextarea"+ID).val();
var dataString = 'comment='+ comment + '&msgid=' + ID;
if($.trim(comment).length===0)
{
alert("Please Enter Comment Text");
}
else
{
$.ajax({
type: "POST",
url: "comment_ajax.php",
data: dataString,
cache: false,
success: function(html){
$(".scroll-pane").load("load_comments.php");
}
});
}
return false;
});
// commentopen
$('.commentopen').on("click",function()
{
var ID = $(this).attr("id");
$("#commentbox"+ID).slideToggle('fast');
return false;
});
$('.close').on("click",function()
{
var ID = $(this).attr("id");
$("#commentbox"+ID).hide('fast');
return false;
});
});
</script>
The ajax works well , the comment gets inserted but the new comment does not get loaded , instead the error :
Notice: Undefined variable: _row in C:\wamp\www\fresh\final\load_comments.php on line 4
Call Stack
# Time Memory Function Location
1 0.0000 147616 {main}( ) ..\load_comments.php:0
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\fresh\final\load_comments.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 147616 {main}( ) ..\load_comments.php:0
2 0.0030 154344 mysql_num_rows ( ) ..\load_comments.php:5
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\fresh\final\load_comments.php on line 8
Call Stack
# Time Memory Function Location
1 0.0000 147616 {main}( ) ..\load_comments.php:0
2 0.0040 154472 mysql_fetch_array ( ) ..\load_commen
please help me to correct the code If not possible , please guide me with a better one
Thanks in advance !