0% found this document useful (0 votes)
10 views2 pages

Extends Public: Parent

This PHP code defines a User controller in CodeIgniter that handles user-related operations. It includes methods for adding a user, saving user data after validation, and displaying all users. The save method checks for required fields and password length before inserting data into the database.

Uploaded by

Idris. S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Extends Public: Parent

This PHP code defines a User controller in CodeIgniter that handles user-related operations. It includes methods for adding a user, saving user data after validation, and displaying all users. The save method checks for required fields and password length before inserting data into the database.

Uploaded by

Idris. S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

<?

php
class User extends CI_Controller
{
public function_construct()
{
parent::__construct();
$this->load->model('M_user','model');
$this->table='users';
}

public function add()


{
$this->load->view('user_add');
}
}

public function save()


{
if(isset($_POST['kirim']))
{
$email = $this->input->post('email');
$pass = $this->input->post('password');
$nama = $this->input->post('nama');

//untuk cek apakah email, password, dan nama sudah terisi


if($email and $pass and $nama)
{
//untuk cek apakah password lebih dari 6 karakter
if(strlen($pass)>6)
{
$data = [
'email'=>$email,
'password'=>$pass,
'nama'=>$nama
]
$this->model->insert_data($this->table,
$data);
}
}

redirect('user/add');
}

}
public function show()
{
$data['users'] = $this->model->get_all_data($this->table);
$this->load->view('user_show',$data);
}

You might also like