0

在此编码中,我检查数据库中是否存在电子邮件 ID。之后我需要更改密码。

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

如果数据库中存在电子邮件,我需要获取“电子邮件 ID 存在”消息,否则我需要获取“错误”消息。我需要如何检查条件。

4

2 回答 2

0

因为您需要检查该电子邮件地址是否已在使用中。所以在模型中

$this->db->where("email",$input['email']);
$query = $this->db->get("users");
if($query->num_rows()>0){
   $status['message'] = 'Email Already Exist';
}
于 2013-07-09T12:04:11.360 回答
0
    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;
    }

//更改模型中的更新函数,如下所示:

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
    }

}
于 2013-07-09T12:06:40.800 回答