Page 1 of 1
Add a null and not a zero "0"
Posted: Sun Nov 26, 2017 11:27 am
by eayvl
Hi, how can I solve the following:
When i add data in another table, if the field is empty a "0" is added in the field "ph_envio", I don't want the zero to be added.
$MyResult = ew_Execute("INSERT INTO historical (ph_userlevel, ph_envio, ph_concep, ph_file) VALUES ('" . Security()->CurrentUserLevelName() ."', '".$rsnew["fe_envio"]."', '".$rsnew["fe_concep"]."', '".$rsnew["fe_file"]."')");
Thanks for the help.
Re: Add a null and not a zero "0"
Posted: Sun Nov 26, 2017 4:11 pm
by mobhar
Add this code before your code above:
if ( empty($rsnew["fe_envio"]) || $rsnew["fe_envio"] == "0") {
$rsnew["fe_envio"] = "";
}
Re: Add a null and not a zero "0"
Posted: Mon Nov 27, 2017 4:16 am
by eayvl
Why it does not work ?
I did a test directly in the INSERT INTO; I put this value directly ->'test' in the field '".$rsnew["fe_envio"]."' and it does not work, continue adding zero "0".
$MyResult = ew_Execute("INSERT INTO historical (ph_userlevel, ph_envio, ph_concep, ph_file) VALUES ('" . Security()->CurrentUserLevelName() ."', 'test', '".$rsnew["fe_concep"]."', '".$rsnew["fe_file"]."')");
I have this code in a table called "f_executive" i tried it in, Row_Inserting and Row_Inserted and it does not work.
Re: Add a null and not a zero "0"
Posted: Mon Nov 27, 2017 10:48 am
by mobhar
Then double check your table schema, probably default value of that field is "0", so that when you are inserting a record to the table, the value always set to "0" for the field.
Re: Add a null and not a zero "0"
Posted: Wed Nov 29, 2017 2:02 am
by sangnandar
- Check your default table value (as mobhar's said).
- Check your default value in Add section in field setup.
- Loose this single quote '".$rsnew["fe_envio"]."' if your field is INT type.