我在为学生注册状态时输入错误消息是否有问题,无论他/她是老同学,新生,受让人。当我输入或再次添加学生的状态时,由于重复输入会导致错误,因为它是一对一的关系,所以我需要设置一个消息,例如表单验证,但仍然会出错重复输入。
这是我的控制器:
function enrollstudent(){
if($this->session->userdata('logged_in'))
{
$this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
$this->output->set_header('Pragma: no-cache');
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$this->load->view('StudentEnroll', $data);
} else{
redirect('welcome', 'refresh');
}
if((!isset($session_data) || $session_data !=TRUE)) {
redirect('welcome', 'refresh');
}
}
function addstatusofenroll($id){
$this->form_validation->set_rules('status', 'Status', 'callback_status_check');
if($this->form_validation->run() == FALSE)
{
$this->enrollstudent();}
else{
$data= array(
'Id'=> $id ,
'Statusofenrollment' => $this->input->post('status')
);
$this->db->insert('statusofenrollment',$data);
$this->session->set_flashdata('category_success', 'Successfully Add!');
$this->load->view('StudentEnroll');
}
}
public function callback_status_check($roll)
{
$this->db->where('Id', $roll);
$query = $this->db->get('statusofenrollment');
$count_row = $query->num_rows();
if ($count_row > 0)
{
echo 'Data Already exist';
$this->session->set_flashdata('warning', 'Data already exists');
return FALSE;
}
else
{
return TRUE;
}
}
答案 0 :(得分:0)
听起来状态不应该是一对一的关系,因为可能有许多学生具有相同的地位。如果您更改数据库以使状态字段不必是唯一的,您应该能够自由地插入和更新每个学生。