Skip to content

Instantly share code, notes, and snippets.

@ronykader
Created February 18, 2017 11:08
Show Gist options
  • Save ronykader/323b4383645805ee1751a831838cc76b to your computer and use it in GitHub Desktop.
Save ronykader/323b4383645805ee1751a831838cc76b to your computer and use it in GitHub Desktop.
You can validation when you will insert data in your database by codeigniter
public function save_football()
{
$login_info = $this->session->userdata('login_info');
if ($login_info['logged_in'] == 1 && $login_info['user_details']['status'] == 1):
$this->form_validation->set_error_delimiters($this->alert->dmStart(), $this->alert->dmEnd());
$data = array('required' => 'Please write %s');
$this->form_validation->set_rules('team_name', 'team name', 'trim|required', $data);
$data = array('required' => 'Please select %s');
$this->form_validation->set_rules('status', 'football status', 'trim|required', $data);
if (empty($_FILES['football_logo']['name']))
{
$data = array('required' => 'Please select %s');
$this->form_validation->set_rules('football_logo', 'team logo', 'required');
}
if ($this->form_validation->run() == FALSE)
{
self::football_form();
}
else
{
if ( !empty($_FILES['football_logo']['name'] ))
{
$football_logo = $this->Football_model->uploadImage('football_logo','football_logo','gif|jpg|png',1);
$attachment = $football_logo['file_name'];
if ( $football_logo['file_name'] == '' )
{
$this->session->set_flashdata('FlsMsg',$this->alert->danger($football_logo['upload_error']));
redirect( 'Football');
}
}
else
{
$attachment = '';
}
$created_by = $login_info['user_details']['id'];
$data = array(
'team_name' => $this->input->post('team_name'),
'description' => $this->input->post('description'),
'football_logo' => $attachment,
'team_image' => $this->input->post('team_image'),
'status' => $this->input->post('status'),
'created_by' => $created_by,
'ip_address' => $_SERVER['REMOTE_ADDR'],
'machine_name' => php_uname('n')
);
$data = $this->security->xss_clean($data);
$football_insert = $this->Football_model->insert_football($data);
if( $football_insert ) :
$this->session->set_flashdata('FlsMsg',$this->alert->success('Team create process'));
redirect( 'Football');
else:
$this->session->set_flashdata('FlsMsg',$this->alert->danger('Team create process'));
redirect( 'Football');
endif;
}
else:
$this->load->view('login/login_signup');
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment