I coded a status-box. It was successful. Then I coded the comments system for the status. It all went fine. But there is a problem in it.
Problem: When there is more than one status posted, it only allows comments on the first status. If I try to post a comment on the second status, it won't load the AJAX request. I tried checking the Dev console too, but it didn't show anything.
Note: I load the statuses by AJAX into the main page. The comment is posted by a JavaScript function, which sends the $.ajax({type: "post"});
request to the file which retrieves the text, user ID and everything from the URL to save it into the database.
Please tell me if there is any logic in it, and what could be the problem.
jQuery AJAX function to POST comment
function send(id, post_id) {
var pos = $("#txt").val();
var post = pos.trim();
if(post !== '') {
$.ajax({
url: 'comment.php?id='+id+'&post_id='+post_id+'&post='+post,
type: "POST",
success: function() {
reload();
}
});
}
}
This is how I call it:
<textarea cols="70" id="txt" placeholder="Write a comment.." class="input-user"></textarea><br />
<br />
<input type="submit" value="Post" style="background: #f2f2f2; width: 60px; height: 40px; padding: 5px; border-radius: 5px;" onclick="javascript:send('<?php echo $_SESSION['id']; ?>', '<?php echo $post['id']; ?>');" />
The comment.php file:
<?php
include("includes/config.php");
include("includes/bbcode.php");
$id = intval($_GET['id']);
$post_id = intval($_GET['post_id']);
$pos = bbcode($_GET['post']);
$post = mysqli_real_escape_string($con, $pos);
$post_comment = mysqli_query($con, "INSERT INTO comments(post_id, user_id, comment) VALUES('".$post_id."', '".$id."', '".$post."')") or die(mysqli_error($con));
?>
Again: All this is working only for the first post, i.e., you can only comment on the first post and if you try to comment on the second or later posts AJAX doesn't even send a request..