function validate_user($email = '' , $password = '', $deviceid = ''){
$result = FALSE;
$credential = array( 'email' => $email , 'password' => $password );
$query = $this->db->get_where('user' , $credential);
if ($query->num_rows() > 0):
$this->db->where($credential);
if
($this->db->where('user' array('token' => IS NULL )));
$this->db->update('user', array('token' => $deviceid ));
$result = TRUE;
endif;
return $result;
}
here is my code i get error on line 7 where i check its null or not.
and if this null i want add device id else if have vale in token exit
My Answer:
You can modify your code as follows to check if the token is null before updating it with the device id:
php
function validate_user($email = '', $password = '', $deviceid = ''){
$result = FALSE;
$credential = array('email' => $email, 'password' => $password);
$query = $this->db->get_where('user', $credential);
if ($query->num_rows() > 0):
$user = $query->row();
if ($user->token === NULL) {
$this->db->where($credential);
$this->db->update('user', array('token' => $deviceid));
$result = TRUE;
} else {
// Token is not null, exit or do something else
exit;
}
endif;
return $result;
}
In this code, we first retrieve the user object from the query result. Then, we check if the token property of the user object is NULL. If it is NULL, we update the token with the device id. Otherwise, we exit the function or perform any other action you want.
Rate this post
5 of 5 based on 2797 votesComments