我如何验证电子邮件存在于ci中的两个表中

时间:2016-12-28 11:19:10

标签: php codeigniter

我有两个表供应商和用户。显示我们如何验证电子邮件是否存在于两个表中。

 $this->form_validation->set_rules('email', 'Email', 'required|is_unique[user.email]|valid_email','call_back_mail',array('required' => 'You have not provided %s.', 'is_unique' => 'This %s already exists.'));

2 个答案:

答案 0 :(得分:1)

Add this in your .php file (controller) 
$form_validation->Form_validation($emails,'Email',"require|validemail|check_unique-admin_details-users_details-email");

//and add this code in the validation.php (library)
case "check_unique":
                    $result= $this->validation_check_unique($data,$name,$key1[1],$key1[2],$key1[3]);
                    break;

//
function validation_check_unique($data="",$name,$table,$table1,$fieldname)
    {

        $sql = mysql_fetch_array(mysql_query("select $fieldname from $table where $fieldname = '$data'"));
        if($data == $sql[0])
        {
            $sql1 = mysql_fetch_array(mysql_query("select $fieldname from $table1 where $fieldname = '$data'"));
            if($data == $sql1[0])
            {
                array_push($this->validation_array,"<i class='fa fa-arrow-circle-right'></i> $name already exist.");
                return FALSE;
            }

        }

    }

答案 1 :(得分:0)

我不反对供应商和用户表是php数组还是sql表?