学生已存在注册系统的验证(Codeigniter)


Student is Already Exist Validation for Enrollment System (Codeigniter)

我是编码新手,我需要一些帮助,如何在添加student时进行验证,它会提示student已经存在,我在这里有一个示例代码来创建student并更新。但是当我添加一个具有相同全名的学生时,如果该学生已经存在,我不知道如何验证它。如果电子邮件si已经存在,我也需要验证我的电子邮件。。

提前谢谢。。希望你能帮我很多忙D

function student($param1 = '', $param2 = '', $param3 = '')
{
    if ($this->session->userdata('admin_login') != 1)
        redirect('login', 'refresh');
    if ($param1 == 'create') {
        $data['name']        = $this->input->post('name');
        $data['birthday']    = $this->input->post('birthday');
        $data['sex']         = $this->input->post('sex');
        $data['address']     = $this->input->post('address');
        $data['phone']       = $this->input->post('phone');
        $data['email']       = $this->input->post('email');
        $data['password']    = md5($this->input->post('password')); 
        $data['father_name'] = $this->input->post('father_name');
        $data['mother_name'] = $this->input->post('mother_name');
        $data['class_id']    = $this->input->post('class_id');
        $data['roll']        = $this->input->post('roll');
        $this->db->insert('student', $data);
        $student_id = mysql_insert_id();
        move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/student_image/' . $student_id . '.jpg');
        $this->email_model->account_opening_email('student', $data['email']); //SEND EMAIL ACCOUNT OPENING EMAIL
        $this->session->set_flashdata('flash_message', get_phrase('add_student_success'));
        redirect(base_url() . 'index.php?admin/student/' . $data['class_id'], 'refresh');
    }
    if ($param2 == 'do_update') {
        $data['name']        = $this->input->post('name');
        $data['birthday']    = $this->input->post('birthday');
        $data['sex']         = $this->input->post('sex');
        $data['address']     = $this->input->post('address');
        $data['phone']       = $this->input->post('phone');
        $data['email']       = $this->input->post('email');
        $data['password']    = md5($this->input->post('password'));
        $data['father_name'] = $this->input->post('father_name');
        $data['mother_name'] = $this->input->post('mother_name');
        $data['class_id']    = $this->input->post('class_id');
        $data['roll']        = $this->input->post('roll');
        $this->db->where('student_id', $param3);
        $this->db->update('student', $data);
        move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/student_image/' . $param3 . '.jpg');
        $this->crud_model->clear_cache();
        $this->session->set_flashdata('flash_message', get_phrase('edit_student_success'));
        redirect(base_url() . 'index.php?admin/student/' . $param1, 'refresh');
    } else if ($param2 == 'edit') {
        $page_data['edit_data'] = $this->db->get_where('student', array(
            'student_id' => $param3
        ))->result_array();
    } else if ($param2 == 'personal_profile') {
        $page_data['personal_profile']   = true;
        $page_data['current_student_id'] = $param3;
    } else if ($param2 == 'academic_result') {
        $page_data['academic_result']    = true;
        $page_data['current_student_id'] = $param3;
    }
    if ($param2 == 'delete') {
        $this->db->where('student_id', $param3);
        $this->db->delete('student');
        redirect(base_url() . 'index.php?admin/student/' . $param1, 'refresh');
    }
    $page_data['class_id']   = $param1;
    $page_data['students']   = $this->db->get_where('student', array(
        'class_id' => $param1
    ))->result_array();
    $page_data['page_name']  = 'student';
    $page_data['page_title'] = get_phrase('manage_student');
    $this->load->view('index', $page_data);
}

请使用这个。

$firstName  = $this->input->post('firstName');
$lastName   = $this->input->post('lastName');
$checkStudentExists = $this->db->get_where('student', array('lastName' => $lastName, 'firstName' => $firstName);
if(count($checkStudentExists) > 0) {
  echo "Student already exists. Please enter another.";
} else {
# Do your code
} 

希望能有所帮助。他们有很多姓氏和名字共存,请添加中间名或生日进行验证

嗨,如果全名已经存在,我会在验证代码中询问这是否正确。。

$name  = $this->input->post('name');
$checkFullnameExists = $this->db->get_where('student', array('name' => $name,);
if(count($checkStudentExists) > 0) {
$this->session->set_flashdata('flash_message', get_phrase('Student is already exists'));
} else {
#do your code
} 

如果电子邮件已经存在,我还需要验证电子邮件。。非常感谢@Shudmeyer。。。