Jump to content

Recommended Posts

Hello,

 

Great site!

 

I am trying to receive back a message from a merchant account after I have posted an order.  The string in "$tx_Result" holds the message and I have entered a sample of I expect to get.  I am trying to strip the message and create variables for insertion into a MySQL DB however I am getting the following error. 

 

Parse error: syntax error, unexpected T_STRING in /test.php(28) : eval()'d code on line 1

 

 

Here is my test code...

<?

$txResult = "trnApproved=1&trnId=10000021&messageId=1&messageText=%3CLI%3EInvalid+expiry+date%3Cbr%3E&trnOrderNumber=10000021&authCode=TEST&errorType=N&errorFields=&responseType=T&trnAmount=827%2E4&trnDate=9%2F9%2F2009+1%3A35%3A43+AM&avsProcessed=0&avsId=0&avsResult=0&avsAddrMatch=0&avsPostalMatch=0&avsMessage=Address+Verification+not+performed+for+this+transaction%2E&cardType=VI&trnType=P&paymentMethod=CC&ref1=&ref2=&ref3=&ref4=&ref5=";

echo "Result:<BR>"; 
echo $txResult."<br>"; 

$special = array('/','','%','+'); 
$txResult = str_replace($special,'',$txResult);



$items = explode('&',$txResult);

foreach ($items as $var) {

	$check = substr($var, -1, 1); 
	   
		if($check == '='){

			eval('return $'. $var . '0;');

		}else{

			eval('return $'. $var . ';');

	}

	echo $var."<br>";

}

echo "<br>";
echo "<br>";
echo "this should be Approval:".$trnApproved."<br>";
echo "this should be Transaction ID:".$trnId."<br>"; 

?>

 

Anyone have any ideas?

 

Thank you in advance!  :D

 

 

Link to comment
https://forums.phpfreaks.com/topic/173656-parse-error-unexpected-t_string/
Share on other sites

Why are you using eval in the first place?

 

<?php
$txResult = "trnApproved=1&trnId=10000021&messageId=1&messageText=%3CLI%3EInvalid+expiry+date%3Cbr%3E&trnOrderNumber=10000021&authCode=TEST&errorType=N&errorFields=&responseType=T&trnAmount=827%2E4&trnDate=9%2F9%2F2009+1%3A35%3A43+AM&avsProcessed=0&avsId=0&avsResult=0&avsAddrMatch=0&avsPostalMatch=0&avsMessage=Address+Verification+not+performed+for+this+transaction%2E&cardType=VI&trnType=P&paymentMethod=CC&ref1=&ref2=&ref3=&ref4=&ref5=";

echo "Result:<BR>"; 
echo $txResult."<br>"; 

$special = array('/','','%','+'); 
$txResult = str_replace($special,'',$txResult);



$items = explode('&',$txResult);
$DBData = array();
foreach ($items as $var) {		
list($name, $val) = explode('=', $var); 
$DBData[$name] = $val;
echo $var."<br>";
}


echo "<br>";
echo "<br>";
echo "this should be Approval:".$trnApproved."<br>";
echo "this should be Transaction ID:".$trnId."<br>"; 
echo "<br /><Br /><pre>";
echo "Cols held\n";
print_r($DBData);
echo "</pre>";
?>

 

That is one way to do it, it is not tested or checked, but "should" work. Basically it creates an associative array ($DBData) where the index is the name and the item held in the index is the value. You can use a foreach loop to iterate this array and put it into a DB/build the SQL statement for the insert. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.