Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:13:18+00:00 2026-06-10T06:13:18+00:00

I have a form in which a user uses to comment on a post.

  • 0

I have a form in which a user uses to comment on a post. Now the hidden input of this form is correct, it gets the correct ‘streamidcontent’ yet when I send it through ajax and into the database it always changes to the last created status id ‘4076’ and adds it to that post at the very top of the feed.
So I’m wondering, what I’m doing wrong.

streamdata_comments

1 comment_id int(11) No None AUTO_INCREMENT
2 comment_poster int(11) No None
3 comment_streamitem int(11) No None
4 comment_datetime datetime No None

FORM

<form id="mycommentform" method="POST"  class="form_statusinput">
<input type="hidden"  name="streamidcontent" id="streamidcontent" value="'.$streamitem_data['streamitem_id'].'">
<input type="input" name"content" id="content" placeholder="Say something" autocomplete="off">
<input type="submit" id="button" value="Feed">
</form>

COMMENT_ADD.PHP

<?php
session_start();
require"include/load.php";
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

if(isset($_POST['streamidcontent'])&isset($_POST['content'])){

        $content =  htmlspecialchars($_POST['content']);
        $streamid = htmlspecialchars($_POST['streamidcontent']);
            $content = preg_replace('/(?<!S)((http(s?):\/\/)|(www.))+([\w.1-9\&=#?\-~%;\/]+)/','<a href="http$3://$4$5">http$3://$4$5</a>', $content);

            $insert = "INSERT INTO streamdata_comments(comment_poster, comment_streamitem, comment_datetime, comment_content) VALUES (".$_SESSION['id'].",'$streamid',UTC_TIMESTAMP(),'$content')";


            $add_post = mysqli_query($mysqli,$insert) or die(mysqli_error($mysqli));
            }

AJAX

<script>
$(document).ready(function(){
$("form#mycommentform").submit(function(event) {
event.preventDefault();
var streamidcontent = $("#streamidcontent").val();
var content = $(this).children('#content').val();

$.ajax({
type: "POST",
url: "comment_add.php",
cache: false,
dataType: "json",
data: { streamidcontent: streamidcontent, content: content}, 
success: function(html){  
$("#containerid").html("<div class='stream_comment_holder' id='comment_holder_"+html['comment_streamitem']+"'><div id='comment_list_"+html['comment_streamitem']+"'><div class='stream_comment' id='comment_"+html['comment_id']+"'>div class='stream_comment_holder' id= style='display:;'><div class='stream_comment'><table width='100%'><tbody><tr><td valign='top' width='30px'><img class='stream_profileimage' style='border:none;padding:0px;display:inline;' border=\"0\" src=\"imgs/cropped"+html['id']+".jpg\" onerror='this.src=\"img/no_profile_img.jpeg\"' width=\"40\" height=\"40\" ></td><td valign='top' align='left'><a href='profile.php?username="+html['username']+"'>"+html['first']+" </a>"+html['comment_content']+"</td></tr></tbody></table></div></div></div></div>");
}
});
return false
});
});
</script>

AND MY OLD AJAX WHICH INSERTED FINE. But I need to add my like, dislike and delete button to this. So changed it to the above AJAX which doesn’t work properly.

function addcomment(streamid,content,containerid,posterid,postername,postid){
var obj = document.getElementById(containerid);
$.post("../comment_add.php", { streamid: streamid,content:content} );
obj.innerHTML = obj.innerHTML + "<div class='stream_comment'><table width='100%'><tbody><tr><td valign='top' width='30px'><img style='border:none;padding:0px;height:30px;width:30px;border-radius:0px;' src='imgs/cropped"+posterid+".jpg' onerror='this.src=&quot;img/no_profile_img.jpeg&quot;;'></td><td valign='top' align='left'><a href='profile.php?username="+posterid+"'>"+postername+" </a>"+content+"</td></tr></tbody></table></div>";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:13:19+00:00Added an answer on June 10, 2026 at 6:13 am

    Have you ever thought that the error might actually be your feed, and not the actual insert? Or it could be the AJAX?

    To verify the insert is working or not, try:

    echo $streamid;  // Shows you're getting the right value from AJAX.
    
    $add_post = mysqli_query($mysqli,$insert) or die(mysqli_error($mysqli));
    if($add_post) {
        $NewID = mysqli_insert_id(mysqli);
        $query = 'SELECT * FROM streamdata_comments WHERE comment_id=' . $NewID;  
        if ($result = mysqli_query($mysqli, $query)) {
            while ($row = $result->fetch_object()){
                var_dump($row);   // Check the actual input is as you expected.
            }
            mysqli_free_result($result);
        }
    }
    

    If using AJAX, you’ll need to monitor results through one of the network tool (press F12 in Chrome, NET panel; or use Fiddler for Win or Charles for Mac)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this login form which uses AJAX to query a database for checking
I have a form which uses reCAPTCHA. For some reason, when a user submits
I have a HTML form which allows a user to add rows ad hoc
I have a form which have many check boxes in it. User will check
I have created a PHP form which requires the user to select a postcode
I have an HTML form which, when submitted by the user, will call a
I have a form with a textfield element which when a user starts typing
I have a web form where I have a textbox in which the user
I have a form allowing a user to signup for a news letter which
I have a jsp form validate.jsp which contains 2 text fields where user enters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.