/*This is my controller: */
public function register()
{
//$this -> output -> enable_profiler( TRUE );
$this -> load -> library( 'form_validation' );
$this -> form_validation -> set_error_delimiters('<div class="error">', '</div>');
$this -> form_validation -> set_rules( 'staff', 'Staff Number', 'trim|required|alpha|min_length[3]|max_length[15]' );
$this -> form_validation -> set_rules( 'firstname', 'First Name', 'trim|required|alpha|min_length[3]|max_length[15]' );
$this -> form_validation -> set_rules( 'lastname', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[15]' );
$this -> form_validation -> set_rules( 'middle', 'Middle Name', 'trim|required|alpha|min_length[3]|max_length[15]' );
$this -> form_validation -> set_rules( 'username', 'User Name', 'trim|required|alpha|min_length[3]|max_length[15]' );
$this -> form_validation -> set_rules( 'password', 'Password', 'trim|required|min_length[4]|max_length[10]' );
$this -> form_validation -> set_rules( 'gender', 'Gender', 'required' );
$this -> form_validation -> set_rules( 'dob', 'DOB', 'required' );
$this -> form_validation -> set_rules( 'status', 'Status', 'required' );
$this -> form_validation -> set_rules( 'role', 'Role', 'required' );
$this -> form_validation -> set_rules( 'street', 'Street', 'required' );
$this -> form_validation -> set_rules( 'area', 'Area', 'required' );
$this -> form_validation -> set_rules( 'city', 'City', 'required' );
$this -> form_validation -> set_rules( 'state', 'State', 'required' );
$this -> form_validation -> set_rules( 'zip', 'Code', 'required' );
$this -> form_validation -> set_rules( 'mobile', 'Mobile', 'required' );
$this -> form_validation -> set_rules( 'home', 'Home', 'required' );
$this -> form_validation -> set_rules( 'email', 'Your Email', 'trim|required|valid_email');
$this -> form_validation -> set_rules( 'image', 'Image', 'required' );
$this -> form_validation -> set_rules( 'degree', 'Qualification', 'required' );
$this -> form_validation -> set_rules( 'college', 'University', 'required' );
$this -> form_validation -> set_rules( 'exp', 'Experience', 'required' );
$this -> form_validation -> set_rules( 'hire', 'Hire', 'required' );
$this -> form_validation -> set_rules( 'term', 'Term', 'required' );
$this -> form_validation -> set_rules( 'ret', 'Retireement', 'required' );
//Setting custom error messages
$this -> form_validation -> set_message( 'min_length', 'Minimum length for %s is %s characters');
$this -> form_validation -> set_message( 'max_length', 'Maximum length for %s is %s characters');
if ( $this -> form_validation -> run() === FALSE )
{
$this->view();
}
else
{
$this->user_model->add_userdetails();
}
}
/ *这是我的模特:
此模型用于将数据插入数据库。我的问题不会将数据存储到数据库中。* /
public function add_userdetails()
{
$this->load->database();
$insert_data=array(
'staff_number'=>$this->input->post('staff'),
'first_name'=>$this->input->post('first_name'),
'last_name'=>$this->input->post('last_name'),
'middle_name'=>$this->input->post('middle'),
'user_name'=>$this->input->post('username'),
'email'=>$this->input->post('email'),
//'password'=>md5($this->input->post('password'))
'password'=>$this->input->post('password'),
'date_oF_birth'=>$this->input->post('dob'),
'status'=>$this->input->post('status'),
'gender'=>$this->input->post('gender'),
'role'=>$this->input->post('role'),
'street'=>$this->input->post('street'),
'area'=>$this->input->post('area'),
'city'=>$this->input->post('city'),
'state'=>$this->input->post('state'),
'zip_code'=>$this->input->post('zip'),
'mobile_number'=>$this->input->post('mobile'),
'home_number'=>$this->input->post('home'),
'other_phone_number'=>$this->input->post('other'),
'email'=>$this->input->post('email'),
'profile_image_path'=>$image_data['image'],
'path' => $image_data['file_path'],
'thumb_path'=> $image_data['file_path'] . 'thumbs/'. $image_data['file_name'],
'spousename'=>$this->input->post('spouse'),
'more_info'=>$this->input->post('more'),
'qualification'=>$this->input->post('degree'),
'university'=>$this->input->post('college'),
'experience'=>$this->input->post('exp'),
'subject_matter_expert'=>$this->input->post('sub'),
'additional_curricular_activities'=>$this->input->post('add_act'),
'rewards_achievements'=>$this->input->post('achieve'),
'memberships'=>$this->input->post('member'),
'address_others'=>$this->input->post('other'),
'date_of_hire'=>$this->input->post('hire'),
'date_of_termination'=>$this->input->post('term'),
'date_of_retriement'=>$this->input->post('ret'),
);
$this->db->insert('staff',$insert_data); //insert data into database
//print_r($insert_data);exit;
}
答案 0 :(得分:0)
$this -> form_validation -> run() === FALSE
更改为$this -> form_validation -> run() == FALSE
add_userdetails()
内,在此行echo $this->db->last_query();die;
后面写$this->db->insert('staff',$insert_data);
并告诉我。