Insert one new record when second table is updated

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

Insert one new record when second table is updated

Post by shkdxb »

i need to insert a new record to table2 whenever any new record or update is done to exisitng records.
trying to include below script in service side event under Table specific row_inserted row_updated but not working.

table1-> IncidentNofromEIT, Callreceived_date, CallResponded_date, TSResponsetimehrs, Product, ProblemRelated, CallcompletedinTSRM_date, ContractStatus, Status,

table2-> IncidentNofromEIT, Callreceived_date, CallResponded_date, TSResponsetimehrs, Product, ProblemRelated, CallcompletedinTSRM_date, ContractStatus, Status, UserName, DateChanged

tried follwing insert but not working

ew_Execute ("INSERT INTO table2( IncidentNofromEIT,, Callreceived_date,CallResponded_date, TSResponsetimehrs, Product, ProblemRelated, CallcompletedinTSRM_date, ContractStatus, Status, UserName, DateChanged )VALUES ( " . $rsnew["IncidentNofromEIT"] . "," . $rsnew["IncidentNofromEIT"] . "," . $rsnew["Callreceived_date"] . "," . $rsnew["CallResponded_date"] . "," . $rsnew["TSResponsetimehrs"] . "," . $rsnew["Product"] . "," . $rsnew["ProblemRelated"] . "," . $rsnew["CallcompletedinTSRM_date"] . "," . $rsnew["ContractStatus"] . "," . $rsnew["Status"])");

what i am doing wrong?

how to capture username and date and time the changes are made in table2?.


mobhar
User
Posts: 11736

Post by mobhar »

  1. Make sure you have enclosed with single quote character for each value which contains date, date/time, string, char, varchar. For example:

    '" . $rsnew["IncidentNofromEIT"] . "', '" . $rsnew["IncidentNofromEIT"] . "', '" . $rsnew["Callreceived_date"] . "', ...

  2. shkdxb wrote:

how to capture username and date and time the changes are made in table2?.

Simply use global function: CurrentUserName() and ew_CurrentDateTime() to get the related value respectively.


shkdxb
User
Posts: 12

Post by shkdxb »

Thanks Mobhar
i am getting error as
Parse error: syntax error, unexpected '"')"' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\phpmaker\eitsla\EITSLAinfo.php on line 1044

now the insert statement is


ew_Execute ("INSERT INTO Changes(
IncidentNofromEIT,, Callreceived_date,CallResponded_date, TSResponsetimehrs,
Product, ProblemRelated, CallcompletedinTSRM_date, ContractStatus, Status, UserName,
DateChanged
)VALUES
( '" . $rsnew["IncidentNofromEIT"] . "','" . $rsnew["IncidentNofromEIT"] . "',
'" . $rsnew["Callreceived_date"] . "','" . $rsnew["CallResponded_date"] . "',
'" . $rsnew["TSResponsetimehrs"] . "','" . $rsnew["Product"] . "',
'" . $rsnew["ProblemRelated"] . "','" . $rsnew["CallcompletedinTSRM_date"] . "',
'" . $rsnew["ContractStatus"] . "','" . $rsnew["Status"]"')");

couldn't find any stray ' or " character.


mobhar
User
Posts: 11736

Post by mobhar »

Double check your SQL, there are some syntax error, such as:

IncidentNofromEIT,, <-- double comma character here

( '" . $rsnew["IncidentNofromEIT"] . "','" . $rsnew["IncidentNofromEIT"] . "', <-- the first and second value are the same?

UserName,
DateChanged
...
VALUES ... ? <-- you have not included the value of both fields in VALUES clausa


shkdxb
User
Posts: 12

Post by shkdxb »

yes noticed your suggestions and included userName and DateChanged, but still i am getting same error

ew_Execute ("INSERT INTO Changes( IncidentNofromEIT,Callreceived_date,CallResponded_date,TSResponsetimehrs,Product,ProblemRelated,CallcompletedinTSRM_date,ContractStatus,Status,UserName,DateChanged
)VALUES
( '" . $rsnew["IncidentNofromEIT"] . "','" . $rsnew["Callreceived_date"] . "','" . $rsnew["CallResponded_date"] . "','" . $rsnew["TSResponsetimehrs"] . "','" . $rsnew["Product"] . "','" . $rsnew["ProblemRelated"] . "','" . $rsnew["CallcompletedinTSRM_date"] . "','" . $rsnew["ContractStatus"] . "','" . $rsnew["Status"]"','" . $rsnew["CurrentUserName()"] . "','" . $rsnew["ew_CurrentDateTime()"] . "')");


scs
User
Posts: 694

Post by scs »

.... $rsnew["Status"]"','" . $rsnew["CurrentUserName()"] ....

See the problem?

$rsnew["Status"] {{{ missing a dot here }}} "','" . $rsnew["CurrentUserName()"]

Should be like this:-

$rsnew["Status"] . "','" . $rsnew["CurrentUserName()"]

I think you better put this in any array and process it.

Otherwise, use external editor to edit the syntax then copy to your program.


shkdxb
User
Posts: 12

Post by shkdxb »

yes the dot solved the problem.
now everything is getting updated in the table2, except username and changed date.

is this syntax is correct?

'" . $rsnew["CurrentUserName()"] . "','" . $rsnew["ew_CurrentDateTime()"] . "'


scs
User
Posts: 694

Post by scs »

Just use CurrentUserName() and ew_CurrentDateTime() will do. No need $rsnew[].


shkdxb
User
Posts: 12

Post by shkdxb »

tried but getting error

Failed to execute SQL. Error: FUNCTION sekarbye_eitsla.CurrentUserName does not exist


scs
User
Posts: 694

Post by scs »

Check phpmaker help with CurrentUserName and/or CurrentUserInfo.

You can get result there.


shkdxb
User
Posts: 12

Post by shkdxb »

sorry not much help available for this CurrentUserName or CurrentUserName
anyone help me pl?


keithh0427
User
Posts: 136

Post by keithh0427 »

Are you using currentUserName()

Note the parantheses


keithh0427
User
Posts: 136

Post by keithh0427 »

In reviewing your posts, you have:

'" . $rsnew["CurrentUserName()"] . "','" . $rsnew["ew_CurrentDateTime()"] . "'

there is not $rsnew['CurrentUserName()"]

Just use CurrentUserName() without $rsnew or the brackets. Same with CurrentDateTime().


shkdxb
User
Posts: 12

Post by shkdxb »

this is what i use

ew_Execute ("INSERT INTO Changes( IncidentNofromEIT,Callreceived_date,CallResponded_date,TSResponsetimehrs,Product,ProblemRelated,CallcompletedinTSRM_date,ContractStatus,Status,UserName,DateChanged )VALUES
( '" . $rsnew["IncidentNofromEIT"] . "',
'" . $rsnew["Callreceived_date"] . "',
'" . $rsnew["CallResponded_date"] . "',
'" . $rsnew["TSResponsetimehrs"] . "',
'" . $rsnew["Product"] . "',
'" . $rsnew["ProblemRelated"] . "',
'" . $rsnew["CallcompletedinTSRM_date"] . "',
'" . $rsnew["ContractStatus"] . "',
'" . $rsnew["Status"] . "',
CurrentUserName(),
ew_CurrentDateTime())");


mobhar
User
Posts: 11736

Post by mobhar »

Try this:

ew_Execute ("INSERT INTO Changes( IncidentNofromEIT, Callreceived_date, CallResponded_date, TSResponsetimehrs, Product, ProblemRelated, CallcompletedinTSRM_date, ContractStatus, Status, UserName, DateChanged ) VALUES
( '" . $rsnew["IncidentNofromEIT"] . "',
'" . $rsnew["Callreceived_date"] . "',
'" . $rsnew["CallResponded_date"] . "',
'" . $rsnew["TSResponsetimehrs"] . "',
'" . $rsnew["Product"] . "',
'" . $rsnew["ProblemRelated"] . "',
'" . $rsnew["CallcompletedinTSRM_date"] . "',
'" . $rsnew["ContractStatus"] . "',
'" . $rsnew["Status"] . "',
'" . CurrentUserName() . "',
'" . ew_CurrentDateTime()) ."'");


shkdxb
User
Posts: 12

Post by shkdxb »

thank you very much. it works now. small correction on last line should read like this

'" . ew_CurrentDateTime() ."')");


Post Reply