PHP Having a small issue with my add comment function

On my website I have a form looking like this:

<div id="addComment">
<form method="post" action="" id="add_comment">
  <label for="Text">Text</label><br />
  <textarea name="Text" id="Text"> </textarea><br />
  <input type="submit" name="submit" id="submit" />

And I'm using codeigniter.

And my controller has this in it:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Image extends CI_Controller {

function index()
    $post['post'] = $this->uri->segment(3);
    $this->load->view('view_post', $post);

public function add_comment(){

    $text = $this->post('Text');
    $url = $this->uri->segment(3);


    $status = "";
    $msg = "";

    if (empty($_POST['Text']))
    $status = "error";
    $msg = "Please enter a title";

   if ($status != "error")
     $file_id = $this->comment_model->add_comment($text, $url);
     if($file_id == true)
        $status = "success";
        $msg = "Comment successfully added";
        $status = "error";
        $msg = "Something went wrong when posting the comment, please try again.";

   echo json_encode(array('status' => $status, 'msg' => $msg));



And in my form "action" I have tried to add "add_comment". But it doesn't seem it helps.. But when I do that. My URL will look like: "" So I guess it's on the right path. But for some reason.. The comment will not be added to my MySql Database..

And here is my model:


class Comment_model extends CI_Model {

   public function add_comment($text, $url)
    $currenttime = date('d F Y H:i:s', strtotime('+1 hour'));

  $data = array(
     'url' => $url,
     'comment' => $text,
     'date' => $currenttime
  $this->db->insert('comments', $data);
  return $this->db->insert_id();

To my eyes everything should be working..... Any help?

Thanks in advance.


I figured out something.. When I add "add_comment" to my forms action this happens: When I remove "index" from the url( It will work.. Then I get "{"status":"error","msg":"Please enter a title"}". But why is my form action adding "index" to the url....?


you didint take the posted value from form in your code

$file_id = $this->comment_model->add_comment($text, $url); 

first you have to store the posted value of form in the $text and $url

like this


second you have to mention action in your form


third you cant take post value in codeignitor like this if (empty($_POST['Text'])) you have to use if (empty($this->input->post('Text')))

Need Your Help

angular $resource delete - passing id parameter

javascript angularjs angular-resource

I'm trying to implement an angular service using $resource. I could implement the query method which returns results. Now I'm blocked with delete service.

Is there a way to detect when all child items within a QTreeWidgetItem have been marked 'hidden'?

c++ qt qtreewidget qtreewidgetitem

Is there a preferred way to detect when all of a QTreeWidgetItem's children are marked as hidden? Currently, I'm iterating over all of them every time any of them are hidden.