データを挿入するフォームがあります。送信ボタンをクリックすると、データはフォームに入力されずにデータベース受信フォームに挿入されません。誰でも私を助けることができます。フォームデータがcodeigniterのデータベースに挿入されない
コントローラ
//load client from table
$data['client'] = $this->project_list_model->get_client();
$this->form_validation->set_rules('location', 'Location', 'required');
$this->form_validation->set_rules('name', 'Project Name', 'required');
$this->form_validation->set_rules('category', 'Category', 'required');
$this->form_validation->set_rules('str_date', 'Start Date', 'required');
$this->form_validation->set_rules('end_date', 'End Date', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('add_project', $data);
} else {
$data = array(
//'staff_id' => ($this->session->userdata['logged_in']['id']),
'project_name' => $this->input->post('name'),
'client_id' => $this->input->post('client'),
'location' => md5($this->input->post('location')),
'start_date' => $this->input->post('str_date'),
'end_date' => $this->input->post('end_date')
);
$result = $this->project_list_model->new_project($data);
$data['message_display'] = 'Add Project Successfully !';
$this->load->view('add_project', $data);
}
}
モデル
// add new project
function new_project($data){
// Inserting in Table(students) of Database(college)
$this->db->insert('project', $data);
}
図
<?php
echo form_open('project_list/add_project');
?>
<!--display successful message-->
<?php
if (isset($message_display)) {
echo "<div class='message alert alert-success'>";
echo $message_display;
echo "</div>";
}
?>
<!--display successful message-->
<?php
//hidden value user session id
echo form_hidden('staff_id',($this->session->userdata['logged_in']['id']));
?>
<div class="form-body">
<div class="form-horizontal" role="form">
<!--client-->
<div class="form-group">
<label class="control-label col-md-1"><b>Client Name </b> </label>
<div class="col-md-9">
<?php
$attributes = 'class = "form-control" id = "client" style="width:80%; height:35px;"';
echo form_dropdown('client',$client, set_value('client'), $attributes);?>
</div>
</div>
<!--client-->
<br>
<!--Category-->
<div class="form-group">
<label class="control-label col-md-1"><b>Category </b> </label>
<div class="col-md-9">
<select name="type" style="width:80%; height:35px;" >
<option selected="selected" >SELECT CATEGORY</option>
<?php
// the gender array
$type = array("New Build", "Maintain");
// Iterating through the type array
foreach($type as $type){
?>
<option value="<?php echo strtolower($type); ?>"><?php echo $type; ?></option>
<?php
}
?>
</select>
</div>
</div>
<!--/.Category-->
<br>
<!--name-->
<div class="form-group">
<label class="control-label col-md-1"><b>Project Name </b> </label>
<div class="col-md-9">
<input type="text" name="name" placeholder="Project Name" style="width:79%; height:25px;" >
</div>
</div>
<!--/.name-->
<br>
<!--location-->
<div class="form-group">
<label class="control-label col-md-1"><b>Location </b> </label>
<div class="col-md-9">
<input type="text" name="location" placeholder="Location" style="width:79%; height:25px;" >
</div>
</div>
<!--/.location-->
<br>
<!--Start Date-->
<div class="form-group">
<label class="control-label col-md-1"><b>Start Date </b> </label>
<div class="col-md-9">
<input type="text" name="str_date" id="str_date" placeholder="Start Date" style="width:79%; height:25px;" >
</div>
</div>
<!--/.Start Date-->
<br>
<!--End Date-->
<div class="form-group">
<label class="control-label col-md-1"><b>End Date </b> </label>
<div class="col-md-9">
<input type="text" name="end_date" id="end_date" placeholder="Start Date" style="width:79%; height:25px;" >
</div>
</div>
<!--/.End Date-->
<br>
<div class="form-group">
<label class="control-label col-md-5"></label>
<div class="col-md-3">
<input type="submit" class="btn btn-success" id="btn btn-success" value="Submit">
<input type="reset" class="btn btn-primary" id="btn btn-primary" value="Reset">
</div>
<div class="col-md-3">
</div>
</div>
<?php
echo form_close();
?>
<!--form_close-->
を検証エラーを印刷することは、あなたは、MySQLから受け取るどのようなエラーを決定するために、インサートの呼び出しの周りにエラー処理を追加します。実際のエラーメッセージがなければ、コードに何が間違っているのかを示すのはやや困難です。 – Shadow