Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login(){
- $username = $this->input->post("username");
- $password = $this->input->post("password");
- $this->db->where("username",$username);
- $this->db->where("password",md5($password));
- $hasil = $this->db->get("tb_user");
- //check query ada datanya apa enggak
- if($hasil -> num_rows() > 0 ){
- //bikin response k mobile
- $data['pesan'] = "login berhasil";
- $data['sukses'] = true ;
- $data['login'] = $hasil->row();
- }
- else{
- $data['pesan'] = "username atau password salah";
- $data['sukses'] = false ;
- }
- echo json_encode($data);
- }
- function register() {
- // Variabel untuk menampung data dari user/mobile/postman
- $nama = $this->input->post('nama');
- $username = $this->input->post('username');
- $email = $this->input->post('email');
- $pass = $this->input->post('password');
- // Ambil data email dari tb_biodata
- $this->db->where('email', $email);
- $check_email = $this->db->get('tb_user');
- // Cek email apakah sudah ada di database
- if($check_email -> num_rows() > 0) {
- $response['status'] = false;
- $response['pesan'] = "Email sudah terdaftar";
- } else {
- // Insert data ke table
- $insert = array();
- $insert['nama'] = $nama;
- $insert['username'] = $username;
- $insert['email'] = $email;
- $insert['password'] = md5($pass);
- $simpan = $this->db->insert('tb_user', $insert);
- if($simpan) {
- $response['status'] = true;
- $response['pesan'] = "Register berhasil";
- }
- else {
- $response['status'] = false;
- $response['pesan'] = "Register gagal, silahkan cek koneksi internet";
- }
- }
- echo json_encode($response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement