我正在研究“发送我的密码”类型的功能,我的 sql 不好或者我的 codeigniter 不好。表单验证得很好,模型中的函数被调用,但没有任何结果。我必须检查提交的电子邮件地址的两个表,因为我们将用户和管理员帐户分成两个表。
控制器代码:
public function send() {
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|trim');
$this->form_validation->set_error_delimiters('<div class="alert alert-error">', '</div><br />');
if ($this->form_validation->run()) {
// Check For A Matching Email
$this->load->model('signin_model');
if ($this->signin_model('email_verify')) {
// There Was A Match
echo "THERE WAS A MATCH";
} else {
// No Match
echo "NO MATCH";
}
} else {
// Form Did Not Validate
$this->load->view('signin/forgot');
}
}
型号代码:
public function email_verify() {
$sql = "SELECT * FROM admin, staff WHERE staff_email = ? OR admin_email = ?";
$email = $this->input->post('email');
$query = $this->db->query($sql, $email, $email);
if($query->num_rows() == 1) {
return true;
} else {
return false;
}
}
错误:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
SELECT * FROM admin, staff WHERE staff_email = 'dsfsdf@test.com' OR admin_email =
更新:我现在使用的固定查询是:
$sql = "SELECT admin_id, first_name FROM admin WHERE admin_email = ? UNION SELECT staff_id, first_name FROM staff WHERE staff_email = ?";