简体   繁体   中英

I want sql query from php if value null then insert else exit

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

It is a bit tricky to give a definitive answer, when it is unclear what kind of object 'db' is, but I would guess your problem is on this line:

($this->db->where('user' array('token' => IS NULL )));

I would suggest you remove the 'IS' from there, so the line would be

($this->db->where('user' array('token' => NULL)));

If this does not help, please expand your question a bit by adding more information of what DB library you are using.

simple syntax error

$this->db->where('user',array('token' => NULL ))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM