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; }
  }
#2

[eluser]bujal[/eluser]
well, is this question too easy for u all since nobody replies Smile
#3

[eluser]bujal[/eluser]
Ghis place really sucks.. Nobody to help huh
#4

[eluser]sv3tli0[/eluser]
The best advice is to check the userguide of CI
http://ellislab.com/codeigniter/user-guide/

In your case check the usage of the flashdata method Smile
http://ellislab.com/codeigniter/user-gui...sions.html
You have to set "$this->session->flashdata('item');" inside your View to see the message which you have set (error or success) Smile

+ you may use Form_validation to grab POST data and to check a field exists in your DB with is_unique check .
http://ellislab.com/codeigniter/user-gui...ation.html




Theme © iAndrew 2016 - Forum software by © MyBB