thnx for you ..
here you re a simple user_model (Models file = typically deal with DB as I learnt) ..
it is just typical method of comparing what user enters with what data we have in db ..
you won't need to see the (View file) I guess .. :)
it's only one row comes back from db, let's say one result comes back , why need to involve that Zero :
row(0)->id; ?!!
to my simple knowledge there is no need for Zero in that bracket .. right ?!
posting screenshot image , has not been uploaded for some reason but here you re : the code :
<?php
class User_model extends CI_Model{
public function register(){
//data array to get all data from the form
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'email' => $this->input->post('email'),
'username' => $this->input->post('user_name'),
'password' => md5($this->input->post('password'))
);
$insert = $this->db->insert('users',$data);
return $insert;
/if this all above go then it will retrun true if not then it will return false, that's why we
testing it there on user.php by if() statement/
}
//login method: is logic funtion that it's able to work there on users.php if($user_id)
public function login($user_name, $password){
//validate with the table
$this->db->where('username',$user_name);
$this->db->where('password',$password);
//restoring the row of the matching in a var
$result = $this->db->get('users');
if($result->num_rows() == 1){ //if there is an actual result
return $result->row(0)->id; //basiclly return the only id from the row , but why the zero !!!
}else{ // if not then do next
return false;
}
}
}
?>
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey, glad I could help.
Can you post a full snippet of code?
thnx for you ..
here you re a simple user_model (Models file = typically deal with DB as I learnt) ..
it is just typical method of comparing what user enters with what data we have in db ..
you won't need to see the (View file) I guess .. :)
it's only one row comes back from db, let's say one result comes back , why need to involve that Zero :
row(0)->id; ?!!
to my simple knowledge there is no need for Zero in that bracket .. right ?!
posting screenshot image , has not been uploaded for some reason but here you re : the code :
<?php
class User_model extends CI_Model{
public function register(){
//data array to get all data from the form
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'email' => $this->input->post('email'),
'username' => $this->input->post('user_name'),
'password' => md5($this->input->post('password'))
);
$insert = $this->db->insert('users',$data);
return $insert;
/if this all above go then it will retrun true if not then it will return false, that's why we
testing it there on user.php by if() statement/
}
?>