need some help regarding about checking if data already exists in the database and system will display a prompt. So this is the code:
In model:
public function check_name($str, $col)
{
$lname = $this->input->post('lastname');
$fname = $this->input->post('firstname');
$result = $this->db->get_where('patients', array(
'firstname' => $lname ,
'lastname' => $fname
));
if($result->num_rows() > 0){
// $this->form_validation->set_message('check_name', 'The %s field already exists.');
echo "Patient with the same name already exists.";
} else {
return true;
}
}
What would be the proper way to call it inside my controller. Code above seems no working.
You have two Parameters in your function which are not used anywhere. Try doing this:
public function check_name($firstname, $lastname)
{
/*
$firstname = $this->input->post('lastname');
$lastname = $this->input->post('firstname');
*/
$query = $this->db->query("SELECT firstname, lastname FROM patients WHERE firstname = ".$firstname." AND lastname = ".$lastname." ");
if($query->num_rows() == 0){
// $this->form_validation->set_message('check_name', 'The %s field already exists.');
echo "Patient with the same name already exists.";
} else {
return true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With