php - Codeigniter error Missing argument -
i've concatenated id of user , pass paramater controller addquestion($id) keep getting these errors:
a php error encountered severity: warning message: missing argument 1 questions::addquestion() filename: controllers/questions.php line number: 49 php error encountered severity: notice message: undefined variable: id filename: controllers/questions.php line number: 67 database error occurred error number: 1048 column 'question_user_id' cannot null insert `questions` (`question_user_id`, `question`) values (null, 'sdf') filename: c:\xampp\htdocs\webdev\askme\system\database\db_driver.php line number: 330
here's view:
<h1>ask users</h1> <ul class="list_items"> <?php foreach ($users $user):?> <li> <div class="list_name"><b><?php echo $user->username;?></b></div> <div class="list_body"><?php echo $user->register_date;?> </div> <div class="list_body"> <a href="<?php echo base_url(); ?>questions/addquestion/<?php echo $user->id; ?>">ask question</a> <!--<?php //echo anchor(//'questions/addquestion/'.$user->id, //'ask question'); ?> --> </div> </li> <?php endforeach; ?> </ul>
and here's addquestion function in controller:
public function addquestion($id) // line 49 { $this->form_validation->set_rules('question','your question','trim|required|xss_clean'); if($this->form_validation->run() == false) { //load view , layout $data['main_content'] = 'questions/add_question'; $this->load->view('layouts/main',$data); } else { //validation has ran , passed //post values array $data1 = array( 'question_user_id' => $id, 'question' => $this->input->post('question') ); if($this->questions_model->create_question($data1)) { $this->session->set_flashdata('question_created', 'question sent'); // redirect index page notification above redirect('home/index'); } } }
please me, dont know what's wrong
you sending null values db field , it's can not null or try make question_user_id
can null $id
can not empty it's required value use check this
else { if(empty($id)) redirect('home'); // redirect page $data1 = array( 'question_user_id' => $id, 'question' => $this->input->post('question') );
Comments
Post a Comment