简体   繁体   中英

select and where condition in codeigniter

In this coding iam checking the whether email id is present in database.After that i need to change password.

function user_password($input, $serviceName){
        $ipJson = json_encode($input);
        $updateArray = array(
            'email' => $input['email'],
            'password' => md5($input['password']),
            'user_modified_date' => date('Y-m-d H:i:s'),
        );
        $this->db->where('email', $input['email']);
        $update = $this->db->update('users', $updateArray);
        if ($update) {
            $data['message'] = 'email id is present';
            $status = $this->clamo_lib->return_status('success', $serviceName, $data, $ipJson);
        } 
        else {
            $data['message'] = 'Error In Updating Please Check Your Email ID';
            $status = $this->clamo_lib->return_status('error', $serviceName, $data, $ipJson);
        }
        return $status;
    }

if email is present in db i need to get "email id is present" message else i need to get "error"message.how i need to check the condition.

As you need to check that email address already in use or not. So in model

$this->db->where("email",$input['email']);
$query = $this->db->get("users");
if($query->num_rows()>0){
   $status['message'] = 'Email Already Exist';
}
    function user_password($input, $serviceName)
    {
         $ipJson = json_encode($input);
         $updateArray = array(
           'email' => $input['email'],
           'password' => md5($input['password']),
           'user_modified_date' => date('Y-m-d H:i:s'),
         );
         $this->db->where('email', $input['email']);
         $update = $this->db->update('users', $updateArray);
        if ($update==TRUE) 
        {
           $data['message'] = 'email id is present';
           $status = $this->clamo_lib->return_status('success', $serviceName, $data,    $ipJson);
        } 
        else 
        {
            $data['message'] = 'Error In Updating Please Check Your Email ID';
            $status = $this->clamo_lib->return_status('error', $serviceName, $data, $ipJson);
        }
        return $status;
    }

//change your update function in model something like this:

function update('users',$updatearray)
{
    if(is_array($dataarray))
    {
       $this->db->trans_start();
       $this->db->where('email',$this->input->post('email'));
       $this->db->update('table',$updatearray);
       $this->db->trans_complete();
       return TRUE;
    }
    else
    {
       return FALSE
    }

}

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