我正在尝试在表格中插入表单值。我不知道未发布值的原因是错误值不能为null我确定我在表单中提到了正确的表值,任何人都可以检查我犯了什么错误
这是我的按钮:
<td><form action="<?php echo base_url();?>Dashboard/ReviewManagement" method="POST">
<input type="hidden" name="topicid" value="<?php echo $proview->id;?>">
<input type="hidden" name="courseid" value="<?php echo $proview->courseId;?>">
<button type="submit" class="btn btn-xs btn-warning" >
<span class="icon-ok"></span>
</button>
</form></td>
这是我的控制人:
public function ReviewManagement() {
$username = $this->session->userdata('user_name');
$data['userslist'] = $this->Dashboard_model->getUsers();
$insert_data = array(
'topicid' =>$this->input->post('topicid'),
'stage' => $this->input->post('stage'),
'allocatedresource' => $this->input->post('allocatedresource'),
'status' => 1,
'createdby' => $username,
'createdon' => date('d/m/Y'),
'expec' =>$this->input->post('expec')
);
$this->Dashboard_model->reviewmanagerInsert($insert_data);
$this->load->view('template/header');
$this->load->view('dashboard/reviewmanagement',$data);
$this->load->view('template/footer');
}
Here is my model:
public function reviewmanagerInsert($data)
{
$this->db->insert('reviewmanager',$data);
}
这是我的观点:
<form action="<?php echo base_url();?>Dashboard/ReviewManagement" method="post">
<div class="form-row">
<div class="col-md-3">Reviewer:</div>
<div class="col-md-9">
<select name="allocatedresource" class="form-control">
<option value="0">Select Reviewer</option>
<?php foreach ($userslist as $users) { ?>
<option value="<?php echo $users->id; ?>"><?php echo $users->username; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-row">
<div class="col-md-3">Stage:</div>
<div class="col-md-9">
<select class="form-control col-md-8" name="stage" required="">
<option value="" selected="">Select Stage</option>
<option value="1">PB Review</option>
<option value="2">PB2 Review</option>
<option value="3">Alpha Review</option>
<option value="4">Beta Review</option>
<option value="5">Gamma Review</option>
</select>
</div>
</div>
<div class="form-row">
<div class="col-md-3">Due Date:</div>
<div class="col-md-9">
<div class="input-group">
<div class="input-group-addon"><span class="icon-calendar-empty"></span></div>
<input type="text" name="expec" autocomplete="off" required="" class="datepicker form-control" value=""/>
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-8 col-md-offset-2">
<button type="submit" class="btn btn-primary btn-block">Assign</button>
</div>
</div>
</form>
收到此错误:
列“ topicid”不能为空
INSERT INTO `reviewmanager`
(`topicid`, `stage`, `allocatedresource`,
`status`, `createdby`, `createdon`, `expec`)
VALUES (NULL, NULL, NULL, 1, 'admin', '16/08/2018', NULL)
有人可以帮我犯什么错误
谢谢。
答案 0 :(得分:0)
仅使用一种具有隐藏字段的表单,并使用类似jquery的值给这些隐藏字段
您的按钮视图
<td>
<div id="topicid" value="<?php echo $proview->id;?>"></div>
<div id="courseid" value="<?php echo $proview->courseId;?>"></div>
<button type="button" class="btn btn-xs btn-warning" >
<span class="icon-ok" id="submit"></span>
</button>
</td>
然后在您的主表单中的隐藏字段下方添加
<input type="hidden" name="topicid" id="topic_id">
<input type="hidden" name="courseid" id="course_id">
然后在js下面添加以分配值
$(document).ready(function(){
$("#submit").click(function(){
var topicid = $("#topicid").val();
var courseid = $("#courseid").val();
$("#topic_id").val(topicid);
$("#course_id").val(courseid);
});
});
此答案未经测试。
答案 1 :(得分:0)
只需在表单的两个输入下方添加...
<input type="hidden" name="topicid" id="topic_id">
<input type="hidden" name="courseid" id="course_id">
答案 2 :(得分:0)
像下面一样解决了
<td><form action="<?php echo base_url();?>Dashboard/ReviewManagement" method="POST">
<input type="hidden" name="topicid" value="<?php echo $proview->id;?>">
<input type="hidden" name="courseid" value="<?php echo $proview->courseId;?>">
<button type="submit" class="btn btn-xs btn-warning" >
<span class="icon-ok"></span>
</button>
</form></td>
从下面更改为秒
<form action="<?php echo base_url();?>Dashboard/ReviewManagementInsert" method="post">
<div class="form-row">
<div class="col-md-3">Reviewer:</div>
<div class="col-md-9">
<select name="allocatedresource" class="form-control">
<option value="0">Select Reviewer</option>
<?php foreach ($userslist as $users) { ?>
<option value="<?php echo $users->username; ?>"><?php echo $users->username; ?></option>
<?php } ?>
</select>
</div>
</div>
控制器代码1:
public function ReviewManagement() {
if ($this->session->userdata('is_logged')) {
if (!empty($this->input->post('topicid'))) {
$id = $this->input->post('topicid');
$data['userslist'] = $this->Dashboard_model->getUsers();
$data['id'] = $this->input->post('topicid');
$this->session->set_userdata('topicid', $data['id']);
$this->load->view('template/header');
$this->load->view('dashboard/reviewmanagement', $data);
$this->load->view('template/footer');
} elseif (!empty($this->session->userdata('topicid'))) {
$id = $this->session->userdata('topicid');
$data['userslist'] = $this->Dashboard_model->getUsers();
$data['id'] = $this->session->userdata('gettopicdetails');
$this->load->view('template/header');
$this->load->view('dashboard/reviewmanagement', $data);
$this->load->view('template/footer');
} else {
echo 'im else';
die;
}
} else {
$this->session->set_flashdata('error', 'Topic Id not captured.');
redirect('Dashboard');
}
}
控制器代码2
public function ReviewManagementInsert() {
$topicid = $this->session->userdata('topicid');
$username = $this->session->userdata('user_name');
$insert_data = array(
'topicid' => $topicid,
'stage' => $this->input->post('stage'),
'allocatedresource' => $this->input->post('allocatedresource'),
'status' => 1,
'createdby' => $username,
'createdon' => date('d/m/Y'),
'expec' => $this->input->post('expec')
);
$this->Dashboard_model->reviewmanagerInsert($insert_data);
$this->load->view('template/header');
$this->load->view('dashboard/reviewmanagement');
$this->load->view('template/footer');
}