php - codeigniter query builder will update db with just about anything -
i'm new codeigniter , trying mind around query builder functionality. have update method pass user entered data update record in db. i've noticed seems successful no matter kind of junk data throw @ it, , i'm wondering if there's setting or need change, or what.
as can see below, in model i'm bypassing user entered value , putting in junk data , still successful. inserts 0000-00-00. dob in db date datatype.
i success result this, , updates db, techically successful. have controls in place prevent junk data ever being sent model, doesn't give me warm fuzzies knowing behaving way.
controller:
$updateresult = $this->patients_model->update_patient_profile($this->data['post_data']); if($updateresult === true) { $this->data['patient_profile'] = $this->patients_model->get_patient_profile($patientid); $this->data['update_result'] = true; $this->load->view('index', $this->data); } else { $this->data['update_result'] = false; print_r($updateresult); }
model:
function update_patient_profile($data) { $patient_id = $data['patient_id']; unset($data['patient_id']); $data['dob'] = 'this not date'; //will store 0000-00-00 in db. $this->db->where('patient_id', $patient_id); $this->db->update($this->patientstable, $data); if($this->db->affected_rows()) { return true; } else { return $this->db->error(); } }
you can check php , thorw error invalid date. try this:
function update_patient_profile($data) { $patient_id = $data['patient_id']; unset($data['patient_id']); $check_date = $data['dob']; if(strtotime($check_date)) { $data['dob'] = date("y-m-d",strtotime($check_date)); // confirm date valid , equivalant database format } else { throw new exception("invalid date", 1); } $data['dob'] = 'this not date'; //will store 0000-00-00 in db. $this->db->where('patient_id', $patient_id); $this->db->update($this->patientstable, $data); if($this->db->affected_rows()) { return true; } else { return $this->db->error(); } }
Comments
Post a Comment