• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED]my approve function doesn't update data tables

#1
[eluser]Unknown[/eluser]
This is my major problem in the system that I'm working I need an onclick approval function that will change the database table tb_comment status from 0 to 1.

my table tb_comment
Code:
CREATE TABLE IF NOT EXISTS `tb_comment` (
  `comment_id` int(255) NOT NULL AUTO_INCREMENT,
  `comment` varchar(500) NOT NULL,
  `name` varchar(500) NOT NULL,
  `status` tinyint(1) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`comment_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
INSERT INTO `tb_comment` (`comment_id`, `comment`, `name`, `status`, `date`) VALUES
(1, 'This is Just a test for the onclick approval', 'my name', 1, '2011-08-20 10:53:07')

my controller
Code:
public function blogs() {
  $this->load->model('m_comment');
  $data['comments'] = $this->m_admin->getAllcomment();
  $this->load->view('adminblogs', $data);
  }  

  public function approve($comment_id){
   $data['status'] = 1;
   $comment_id = $this->input->post('comment_id');
   $status = $this->input->post('status');
   $this->load->model('m_admin');
   $this->m_admin->updateComment($comment_id,$data);
   $this->session->set_flashdata('message','Comment'.$comment_id.' has been approved');
   redirect('admin/blogs','refresh');
  }

my model
Code:
public function approveComment($comment_id,$status){
   $this->db->where('comment_id',$comment_id);
   $this->db->update('tb_comment',$status);
  }

  public function getAllcomment() {
  $this->db->where('status =',0);
  $this->db->order_by("comment_id","desc");
  $query = $this->db->get('tb_comment');
  if($query->num_rows() >= 0) {
  foreach ($query->result() as $row) {
    $data[] = $row;
    }
   return $data;
   }
  }

my views
Code:
<?php foreach ($comments as $commentsItem):?>
<?php echo form_open('admin/blogs'); ?>

<?php echo form_hidden('comment_id',$commentsItem->comment_id); ?>    
<tr>
<th width="200">&lt;?php echo $commentsItem->name;?&gt;</th>
<th width="700">&lt;?php echo $commentsItem->comment;?&gt;</th>


<th width="75">&lt;?php echo anchor('admin/approve/'.$commentsItem->comment_id,'Approve',array('onclick' => "return confirm('The comment of $commentsItem->comment_id {$commentsItem->name},  will be posted. Do you want to continue?')"));?&gt;</th>
<th width="75">&lt;?php echo anchor('admin/updatecomment/'.$commentsItem->comment_id,'Edit');?&gt;</th>
<th width="75">&lt;?php echo anchor('admin/deletecomment/'.$commentsItem->comment_id,'Deny',array('onclick' => "return confirm('The comment of {$commentsItem->name},  will be posted. Do you want to continue?')"));?&gt;</th>

</tr>
&lt;?php echo form_close(); ?&gt;
&lt;?php endforeach;?&gt;
</tbody>
</table>

thank you I'm really having a hard time but I think one of my problems is that I used form_hidden for my comment_id.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.