I'm getting this 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 '@gmail.com' at line 1
Here's the code:
$email = $this->input->post('email');
$checkEmail = $this->crud_model->retrieve_where('employee', 'email', 'email', $email);
crud_model:
function retrieve_where($table, $table_id, $table_name, $value) {
$table = $this->db->query('Select * FROM ' . $table . ' Where ' . $table_id . ' = ' . $value);
$records = array();
foreach ($table->result() as $row) {
$records[] = $row->$table_name;
}
return $records;
}
The query that you try to execute is:
SELECT * FROM Email WHERE Email = email@email.com
Email is in this case a string, and a string needs to be quoted.
function retrieve_where($table, $table_id, $table_name, $value) {
$table = $this->db->query("Select * FROM " . mysql_real_escape_string($table) . " Where " . mysql_real_escape_string($table_id) . " = '" . mysql_real_escape_string($value) ."'");
$records = array();
foreach ($table->result() as $row) {
$records[] = $row->$table_name;
}
return $records;
}
Dont forget to escape your query with mysql_real_escape_string()
. It will protect you against injections.