I have a problem in putting error message for the status of enrollment for student whether he/she Old Student, New Student, Transferee. When I input or add again the status of student, it will error due to duplicate entry because it is one-to-one relationship, so I need to set a message such as form validation but still it will error duplicate entry.
here is my controller:
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;
}
}
It sounds like the status shouldn't be a one-to-one relationship because there can be many students with the same status. If you change your database so the status field does not need to be unique, you should be able to insert and update each student freely.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments