As best as I can tell from the code you supplied, you use $transaction_id as function argument but do not declare before such use.
Although you can just declare a symbol anywhere, you cannot use the symbol unless it is already declared.
$some_symbol = 0
function($some_symbol); // now OK
in your second code block you have:
but, you'll observe, your declaration of $transaction_id is commented out.