Add a null and not a zero "0"

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
eayvl
User
Posts: 315

Add a null and not a zero "0"

Post 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.


mobhar
User
Posts: 11703

Post by mobhar »

Add this code before your code above:

if ( empty($rsnew["fe_envio"]) || $rsnew["fe_envio"] == "0") {
$rsnew["fe_envio"] = "";
}


eayvl
User
Posts: 315

Post 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.


mobhar
User
Posts: 11703

Post 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.


sangnandar
User
Posts: 980

Post by sangnandar »

  1. Check your default table value (as mobhar's said).
  2. Check your default value in Add section in field setup.
  3. Loose this single quote '".$rsnew["fe_envio"]."' if your field is INT type.

Post Reply