Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. function add()
  2. {
  3. $this->load->library('form_validation');
  4. $this->load->helper('form');
  5.  
  6. //neu ma co du lieu post len thi kiem tra
  7. if($this->input->post())
  8. {
  9. $this->form_validation->set_rules('name', 'Tên', 'required|min_length[8]');
  10. $this->form_validation->set_rules('username', 'Tài khoản đăng nhập', 'required|callback_check_username');
  11. $this->form_validation->set_rules('password', 'Mật khẩu', 'required|min_length[6]');
  12. $this->form_validation->set_rules('re_password', 'Nhập lại mật khẩu', 'matches[password]');
  13.  
  14. //nhập liệu chính xác
  15. if($this->form_validation->run())
  16. {
  17. //them vao csdl
  18. $name = $this->input->post('name');
  19. $username = $this->input->post('username');
  20. $password = $this->input->post('password');
  21.  
  22. $data = array(
  23. 'name' => $name,
  24. 'username' => $username,
  25. 'password' => md5($password)
  26. );
  27. if($this->admin_model->create($data))
  28. {
  29. //tạo ra nội dung thông báo
  30. $this->session->set_flashdata('message', 'Thêm mới dữ liệu thành công');
  31. }else{
  32. $this->session->set_flashdata('message', 'Không thêm được');
  33. }
  34. //chuyen tới trang danh sách quản trị viên
  35. redirect(admin_url('admin'));
  36. }
  37. }
  38.  
  39. $this->data['temp'] = 'admin/admin/add';
  40. $this->load->view('admin/main', $this->data);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement