i am trying to check if an id in the database already exists and if it does not then only insert that id and not the other ones that exist
I have tried to do a where sta
Model
load->database();
}
function check()
{
$query = null; //emptying in case
$id = $_POST['id']; //getting from post value
$name = $_POST['name'];
$query = $this->db->get_where('fruits', array(//making selection
'id' => $id
));
$count = $query->num_rows(); //counting result from query
if ($count === 0) {
$data = array(
'name' => $name,
'id' => $id
);
$this->db->insert('fruits', $data);
}
}
}
?>