Jump to content

unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM


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

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.