insert/update null instead of blank (spaces) in ci4 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31) +--- Thread: insert/update null instead of blank (spaces) in ci4 (/showthread.php?tid=80368) |
insert/update null instead of blank (spaces) in ci4 - Halim - 10-24-2021 Is there a better way to clean up the data before insert/update, what I mean by clean up is: if the posted value is blank (or composed of many spaces) then insert null, I noticed some other php frameworks, they do that automatically, if the value is blank (or many spaces) it's automatically considered like null value and insert/update like null, In my case: I'm thinking maybe to create a helper (see below) that do this for me but I'm not sure if CodeIgniter already has something already exist. What I noticed too is: if the value contains space at the right it is not trimmed, unless you add trim function to every posted value PHP Code: public function update_social_infos() { my helper function to convert empty strings to NULL PHP Code: function empty2null($value) { Then use something like this: PHP Code: $data = [ Thank you! RE: insert/update null instead of blank (spaces) in ci4 - nfaiz - 10-25-2021 (10-24-2021, 06:10 PM)Halim Wrote: Is there a better way to clean up the data before insert/update, what I mean by clean up is: if the posted value is blank (or composed of many spaces) then insert null, Sometimes we need to save that space value. PHP Code: $data = [ |