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

  • Home
  • SEARCH
  • 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 9268369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:47:41+00:00 2026-06-18T14:47:41+00:00

I have created a comment library to handle comments all over my website developed

  • 0

I have created a comment library to handle comments all over my website developed by CI

I am adding comments using ajax so i have came up with practice to have the function located in MY_Controller that handle the ajax

public function comment_add()
    {
        echo $this->comments->add(); 
    }

and in AJAX Jquery code noting that category is one of controller names as any controller will havethe access to comment_add() found in parent controller

$('#myform').submit(function(e) {

    e.preventDefault();
    dataString=$("#myform").serialize();

  $.ajax({
    type:"POST",
    url: base_url+"snc/category/comment_add",
    data: dataString,
    success: function(data){
        $(data).hide().insertAfter('#inserAfterThis').slideDown('slow');
        $('#comment_new').val('');
        }
    }
  );
});   

and in my Comments library

public function add()
    { 
        $post_id=$this->get_post_id();
        $post_type=$this->get_post_type();

        if(!$post_id || !$post_type || !$this->user_id)
            return false;

        $id=$this->ci->comments_model->comment_add($this->user_id,$post_id,$post_type);
        if($id)
        {
            return $this->_markup($id);
        }
        else
            return false;
    }

and comments model

function comment_add($user_id,$post_id,$post_type)
{

    $data['comment_user_id']=$user_id;
    $data['comment_post_type']=$post_type;
    $data['comment_post_id']=$post_id;
    $data['comment_text']=$this->input->post('comment_new');

    $this->db->insert('comments', $data);

    if($this->db->affected_rows()>0)
        return $this->db->insert_id();
    else
        return false;

}

Problem is that Comment is inserted twice and as well in database twice, i have been tracin this for hours even with x-Debugg found that he go through echo $this->comments->add(); twice dunno why he would do that, thanks for your help

  • 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-18T14:47:43+00:00Added an answer on June 18, 2026 at 2:47 pm

    Found out that I have loaded Jquery file twice, that was my bad, thanks guys

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

Sidebar

Related Questions

I have created a RESTful PHP web service using Lithium which contains comments, each
I have created an android application that calls (using kSOAP library) a SOAP based
I have created infopath form library in SharePoint sever2010. I am using Windows server
A user can create a post. Posts have comments. A comment must belong to
In a php application, I took over JPG files are created using the imagejpeg
I have a problem here. I have created the namespace for all classes. previously
In my current rails app I'm using an ajax uploader library that requires you
I use the Jahmm library for classification of accelerometer sequences. I have created my
I have the need to create Sharepoint blog comments by code: SPSecurity.RunWithElevatedPrivileges(delegate() { sw.AllowUnsafeUpdates
I have created a QWidget with a bunch of QToolButtons in it and I

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.