paingod Posted September 9, 2009 Share Posted September 9, 2009 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! Link to comment https://forums.phpfreaks.com/topic/173656-parse-error-unexpected-t_string/ Share on other sites More sharing options...
p2grace Posted September 9, 2009 Share Posted September 9, 2009 I just tested the code you provided and I didn't receive any syntax issues... so the issue probably exists in the return value of $var. Link to comment https://forums.phpfreaks.com/topic/173656-parse-error-unexpected-t_string/#findComment-915469 Share on other sites More sharing options...
premiso Posted September 9, 2009 Share Posted September 9, 2009 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. Link to comment https://forums.phpfreaks.com/topic/173656-parse-error-unexpected-t_string/#findComment-915491 Share on other sites More sharing options...
paingod Posted September 9, 2009 Author Share Posted September 9, 2009 Thank you so much for your help. This fixed the problem.... $queryString = $txResult; $newVars = array(); parse_str($queryString, $newVars); $vars = array_merge($newVars); $trnApproved = $vars["trnApproved"]; Link to comment https://forums.phpfreaks.com/topic/173656-parse-error-unexpected-t_string/#findComment-915623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.