I'm working on a "send my password" type functionality and either my sql is bad or my codeigniter is bad. The form validates just fine and the function in the model gets called but nothing comes back out. I have to check two tables for the submitted email address because we separated user and admin accounts into two tables.
Controller Code:
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');
}
}
Model Code:
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:
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 = '[email protected]' OR admin_email =
UPDATE: The fixed query I'm now using is:
$sql = "SELECT admin_id, first_name FROM admin WHERE admin_email = ? UNION SELECT staff_id, first_name FROM staff WHERE staff_email = ?";
adminandstafftables? If there is, you need to add that to yourWHERE. If not, you need to either use 2 queries or aUNION.