Jump to content

unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM


bravo14

Recommended Posts

Hi Guys

 

I have got a page generating the following error

 

Error:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sites/trade-bidz.co.uk/public_html/functions/reg_functions.php on line 3

 

The offending code is below (I have removed some of the URL due to security.

 

<?php
function getVehData(){
$file="https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm=$_POST['veh_reg']";
$dom=new DOMdocument();
$dom->load($file);
$xml=simplexml_import_dom($dom);
echo('<tr><td>Make<td></td></tr>
<tr><td>Model<td></td></tr>
<tr><td>Make<td></td></tr>
<tr><td>Date of Manufacture<td></td></tr>
<tr><td>First Registered<td></td></tr>
<tr><td>Colour<td></td></tr>
<tr><td>Body<td></td></tr>
<tr><td>No. of Doors<td></td></tr>
<tr><td>Engine Size (cc)<td></td></tr>
<tr><td>Fuel Type<td></td></tr>
<tr><td>Gearbox Type<td></td></tr>
<tr><td>Previous Owners<td></td></tr>
<tr><td>BHP<td></td></tr>
<tr><td>Emissions<td></td></tr>
</table>
');
}
?>

 

try:

you need to concatenate the post variable into the string:

".$_POST['veh_reg']."

$file="https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm=".$_POST['veh_reg']."";

 

looks like your

$_POST['veh_reg']

isnt escaping properly in the string.

When embedding array variable element into a string you need to omit the inner single quotes in its brackets:

 

$file = "https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm=$_POST[veh_reg]";

You can also use curly brackets to surround the array reference:

<?php
$file = "https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm={$_POST['veh_reg']}";
?>

 

Ken

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.