Jump to content

Parse error, unexpected T_STRING


paingod

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.