我正在处理用户注册表单。我正在尝试使用户必须拥有尚未在系统中注册的电子邮件地址。
我认为该is_unique
功能不起作用,因为所有电子邮件地址数据都以 Base64 编码格式存储,并且查询以未编码格式提交。
我已经尝试在我的控制器和模型中调整它看起来合适的东西,但我最终遇到了错误。
这是我的控制器的功能:
function check_physician_email($physician_email){
$physician_email_check=$this->model_site->get_single_record( 'physicians', 'email', $physician_email );
if($physician_email_check){
$this->form_validation->set_message('check_physician_email', 'The %s is already taken!');
return FALSE;
}
else {
return TRUE;
}
}
使用这个模型:
function get_single_record( $table_name, $primary_key_name, $primary_key_val ) { //get a record with a given condition from table
$query = $this->db->get_where($table_name, array( $primary_key_name => $primary_key_val));
if( $query->num_rows() > 0 ) {
return $query->row_array();
}
else {
return false;
}
} //end get_single_record
当那不起作用时,我开始指向它get_email_record
并在我的模型中尝试了以下几种变体:
function get_email_record( $table_name, $primary_key_name, $primary_key_val ) { //get a record with a given condition from table
$query = $this->db->get_where('physicians', array( encode_decode($_REQUEST['email'], 'decode') => $primary_key_val));
if( $query->num_rows() > 0 ) {
return $query->row_array();
}
else {
return false;
}
} //end get_email_record
这只会导致encode_decode error
:
Error Number: 1300
Invalid utf8 character string: '\xB2\xB6\xACr\x19\xDA\xB5\xB8\xA8r\x8A\xE9r\x89'
SELECT * FROM (`physicians`) WHERE `²¶¬rÚµ¸¨rŠér‰` = 'user@email.com'
Filename: /usr/sites/phototherapydoctor.com/www/html/models/model_site.php
Line Number: 92
如果我在我的模型中这样做:
function get_email_record( $table_name, $primary_key_name, $primary_key_val ) { //get a record with a given condition from table
$query = $this->db->get_where('physicians', array( 'email' => encode_decode($_REQUEST[$primary_key_val],'encode')));
if( $query->num_rows() > 0 ) {
return $query->row_array();
}
else {
return false;
}
} //end get_email_record
我明白了Undefined index error
:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: user@email.com
Filename: models/model_site.php
Line Number: 92