AnsweredAssumed Answered

Web publishing PHP coding question

Question asked by edwardlscott on Jul 20, 2017
Latest reply on Jul 20, 2017 by APIcoder

I'm working on a solution for a client.  Flow: A mass-mailing script sends out formatted html emails using a handy plugin.  The html includes links intended for recipients to click and review the web content of the links (standard web pages).


The links embedded in the html email are not directly to the web pages, but to a PHP script on an FM Server (passes in a parameter).  In the PHP script, it redirects the user back to their link of interest.  The rest of the PHP script writes a record to a FMS hosted database.  All this is working nicely.


I'm pretty new with PHP code.  I am trying to use the last part of my PHP script to write out a textual log file (on the FM server) immediately after the command->execute step that calls the FileMaker script in my solution file.  Intent: It should do one thing if the "command->execute" successfully runs and another if it encounters any errors.


Here is my PHP code beginning with the command that executes the FileMaker-side script (the execute works fine):


$result = $command->execute();


// write a log file of errors and successes

$timestamp = date("m/d/Y")." @ ".date("h:i:sa");



$logfile = fopen("Log_PHP_TXA_Responder.txt", "a+") or die("Unable to open file!");

fwrite($logfile, $timestamp.": ".$result."\r\r");  // Writes out any error message in $result




// Beyond here is the problem, I cannot get this to execute for the life of me

$logfile = fopen("Log_PHP_TXA_Responder.txt", "a+") or die("Unable to open file!");

fwrite($logfile, $timestamp.": Successful update for ".$campaign.", ".$aianum.", ".$urlclick."\r\r");





When there is an error (like say I change the execute-context-layout name to have a typo in it) the first If statement correctly writes my message to the log file (then exits as intended). If there is no error, I would expect the first IF statement to get skipped and for last four lines to execute instead.  I've tried wrapping them in If statements that are always true and everything I can think of, it seems like the PHP script simply stops executing after the curly bracket at the end of the first If statement.


Any help would be much appreciated.


Thanks in advance,