Я хочу сделать простую систему экзаменов Идея состоит в том, чтобы задать вопрос из формы ниже, а затем отправить значения с данными ниже , поэтому я хочу отправить проверенный ввод в столбце с именем правильный ответ и отправьте оба столбца с именами вариантов. любые идеи?Codeigniter: передача значения радио в базу данных
я иметь такую форму в представлении
<form action="<?php echo base_url('home') ;?>" method="post">
<input type="text" name="question" placeholder="Enter question here"><br>
<label>choose the right answer</label><br>
<input type="radio" name="answer" value="first"> <input type="text" placeholder="first choice"><br>
<input type="radio" name="answer" value="second" checked><input type="text" placeholder="second choice"><br>
<input type="submit" value="sumbit" name="ask">
</form>
Это мой контроллер:
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model('exams_model') ;
}
public function index(){
$this->load->view('vieww') ;
if($this->input->post('ask')) {
$this->exams_model->add_question() ;
}
}
}
& это модель:
class Exams_model extends CI_Model{
public function add_question(){
$data = array(
'question' => $this->input->post('question') ,
'choices' => $this->input->post('#') , // here i want to send both inputs (the checked and non checked input
'right_answer' => $this->input->post('#') // i want to pass the checked input to the column right answer in the database
);
$insert = $this->db->insert('exams' , $data);
return $insert ;
}
}