Thursday 15 July 2010

php - Unable to retrieve and id from posted data -



php - Unable to retrieve and id from posted data -

i trying add together comments on joke thread, having problem grabbing joke_id should used amend comments on post.

the problem face is, thread no comments on not add together joke_id database, , thread comments on works fine. have no thought why.

this working illustration of talking about:

http://ehustudent.co.uk/cis21732825/cis3122/jokehut_4/read/joke/14

this thread working (i emphasised joke_id test purposes)

and thread not work:

http://ehustudent.co.uk/cis21732825/cis3122/jokehut_4/read/joke/4

the comment , name added database, joke_id downwards '0' , have no thought why.

here code in view:

<?php //assigning values foreach($results $row){ $name = $row->name; $joke = $row->joke; $joke_id = $row->joke_id; $date_added = $row->date_added; $vote = $row->vote; ?> } echo form_open('comments/insertcomment'); ?> <div class="new-com-bt"> <span>write comment ...</span> </div> <div class="new-com-cnt"> <input type="text" id="name-com" name="name-com" value="" placeholder="name optional" /> <textarea required="yes" class="the-new-com" id="the-new-com" name="the-new-com" placeholder="write comment here..."></textarea> <input type="hidden" name="joke_id" value="<?= $joke_id; ?>"> <input class="bt-add-com" type="submit" value="post comment"> <div class="bt-cancel-com">cancel</div> </div> <div class="clear"></div> <?php echo form_close(); ?>

here controller:

public function index(){ $this->getcomment(); } public function getcomment(){ $data['results'] = $this->comments_m->getcomments(); $this->load->view('template/header'); $this->load->view('template/sidebar'); $this->load->view('content/comment_box', $data); $this->load->view('template/footer'); } public function insertcomment(){ $data = array ( 'user' => 'user', 'comment' => 'comment', 'joke_id' => 'joke_id', 'id_post' => 'joke_id' ); $joke_id = $this->input->post('joke_id'); $this->comments_m->insertcomment($data); redirect(base_url('read/joke/'.$joke_id)); }

}

model:

//gets comments function getcomments ($joke_id){ $query = $this->db->query("select c.name, j.*, co.* jokes j left bring together category c on c.category_id = j.category_id left bring together comments co on co.joke_id = j.joke_id j.joke_id = '$joke_id' ") or die("no results found" ); if ($query->num_rows > 0) { homecoming $query->result(); } } //inserts comments function insertcomment (){ $data = array ( 'user' => $this->input->post('name-com'), 'comment' => $this->input->post('the-new-com'), 'joke_id' => $this->input->post('joke_id'), 'id_post' => $this->input->post('joke_id') ); if(strlen($data['user']) < 1){ $data['user'] = "guest"; } $this->db->insert('comments', $data); }

comments table:

create table if not exists `comments` ( `id` int(11) not null auto_increment, `user` varchar(40) not null, `comment` text not null, `joke_id` int(11) not null, `id_post` int(11) not null, `date` timestamp not null default current_timestamp, primary key (`id`) ) engine=innodb default charset=latin1 auto_increment=1 ;

jokes table:

create table if not exists `jokes` ( `joke_id` int(11) not null auto_increment, `joke` varchar(1024) not null, `category_id` int(11) not null, `vote` int(255) not null, `date_added` timestamp not null default current_timestamp on update current_timestamp, primary key (`joke_id`) ) engine=innodb default charset=latin1 auto_increment=1 ;

any help why joke_id doesn't insert/show on pages no jokes great.

thank you

php mysql sql codeigniter

No comments:

Post a Comment