Welcome Guest, Not a member yet? Register   Sign In
experts help me on this code..
#1

[eluser]bujal[/eluser]
I would like to check if user exist in the database when creating new account. with this codes when I try to create user which is already exist in the database, the message user already exist doesn't appear. instead the flash message displayed saying that account is created. But nothing stored in the database.I m not sure where is the error. this is 1st time using codeigniter, appreciate help from experts..thanks
How if I want to check both $nameStaf & $noStaf already exist??
Code:
controller codes

public function register_account()
{
    $query = $this->modeluser->createAccount();

    $this->session->set_flashdata('mesej', '<span class="label label-info">Account created!</span> ');
    redirect(base_url().'admin/register');

Code:
class ModelUser extends CI_Model {

    public function createAccount()
    {
        $nameStaf   =   $_POST['nama_staf'];
        $noStaf     =   $_POST['no_staf'];
        
        if ($this->checkUser_exist($nameStaf) == false)
            return  USER ALREADY EXIST';

        $this->db->query("INSERT INTO akaun (nama_staf,no_staf)
        VALUES ('$namaStaf','$noStaf')");

    }

Code:
private function checkUser_exist($nameStaf)
  {
     $this->db->where('nama_staf'', $nameStaf );
     $query = $this->db->get('akaun');
     if( $query->num_rows() == 0 ){ return TRUE; } else { return FALSE; }
  }


Messages In This Thread
experts help me on this code.. - by El Forum - 08-11-2013, 01:28 AM
experts help me on this code.. - by El Forum - 08-11-2013, 02:33 AM
experts help me on this code.. - by El Forum - 08-11-2013, 05:34 AM
experts help me on this code.. - by El Forum - 08-11-2013, 05:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB