This is my controller code which save data in table but when I put more than max length column data , it is not retuning me STATUS false; nothing is happening. please help
function saveImproveUs(){
$status =array("STATUS"=>"false");
try{
$improveUs = array(
'NAME' => trim($this->input->post('name')),
'EMAIL' => trim($this->input->post('email')),
'LOCATION' => trim($this->input->post('location')),
'MESSAGE_TYPE' => trim($this->input->post('messageType')),
'COMMENTS' => trim($this->input->post('comments'))
);
// Save improve us
$this->db->insert('trn_improve_us', $improveUs);
if ($this->db->affected_rows() > 0){
$status = array("STATUS"=>"true");
}
}catch(Exception $ex) {
//show_error($ex);
echo "I am in exception";
exit;
}
echo json_encode (array($status)) ;
}
You have to throw the exception, it won't do this for you.
if ($this->db->affected_rows() > 0){
$status = array("STATUS"=>"true");
}
else {
throw new Exception("Could not insert data");
}
Also inserting more data than a column can hold will automatically get cut-off in MySQL, the insert won't actually fail. You should use strlen
to check the length of a string and validate it manually.