実際に私は$ students配列の学生レコードを持っていますが、名前はスキル[]で、チェックボックスのフォームフィールド名である$ students内に別の配列があります。 json_encodeとwhereを使用する。データがcodeigniterのデータベースに挿入されていません
入力フォーム
<td>ENTER SKILLS</td>
<td>
<input type="checkbox" name="skills[]" value="php">php<br>
<input type="checkbox" name="skills[]" value="dotnet">dotnet<br>
<input type="checkbox" name="skills[]" value="java">java<br>
<input type="checkbox" name="skills[]" value="ruby_on_rails">ruby_on_rails<br>
</td>
コントローラ
<?php
public function insert(){
if ($this->input->post('add')==true)
{
$student = array('name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'skills' => $this->input->post(json_encode(skills)),
'notes' => $this->input->post('notes'),
'gender' => $this->input->post('gender'));
$result = $this->Student_info_model->insertStudent($student);
if($result==true){
echo "inserted";
}
else {
echo "Not Inserted";
}
}
}
?>
モデル
function insertStudent($student){
$this->db->insert('student_info_table', $student); // insert data into "student_info_table" table`
if ($this->db->affected_rows() > 0) {
return true;
}
else {
return false;
}
}
エラー
Error Number: 1048
Column 'skills' cannot be null
INSERT INTO `student_info_table` (`name`, `email`, `skills`, `notes`, `gender`) VALUES ('gailyn', '[email protected]', NULL, 'dsas', 'male')
Filename: C:/xampp/htdocs/codeigniter/system/database/DB_driver.php
Line Number: 691
を使用してそれを変換する必要があります: 'の$ this - >入力 - >ポスト(json_encode(スキル)) '?スキルだけ? –
「挿入済み」または「挿入されていません」と表示されますか? – wallyk
ええ、どこが間違っていますか? –