Hi I am using the code below, which I know works in another page on my site, however for this purpose I have put it within a standalone button that runs the script as server side, it is not working and is getting the Fatal error: Using $this when not in object context
(the $$postcode= $params["value1"]; is a result from previous javascript which fetches the current field (postcode) from the add screen, it works and is tested, but its the rest of code.
Id be grateful for some alternatives?
$postcode= $params["value1"];
//Set Post Code Variables
$Key = "xxxx-xxxx-xxxx-xxxx";
$SearchTerm = $postcode;
$this->Key = $Key;
$this->SearchTerm = $SearchTerm;
//Build URL Request
$url = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/xmla.ws?";
$url .= "&Key=" . urlencode($this->Key);
$url .= "&SearchTerm=" . urlencode($this->SearchTerm);
//Make the request to Postcode Anywhere and parse the XML returned
$file = simplexml_load_file($url);
//Check for an error, if there is one then throw an exception
if ($file->Columns->Column->attributes()->Name == "Error")
{
throw new Exception("[ID] " . $file->Rows->Row->attributes()->Error . " [DESCRIPTION] " . $file->Rows->Row->attributes()->Description . " [CAUSE] " . $file->Rows->Row->attributes()->Cause . " [RESOLUTION] " . $file->Rows->Row->attributes()->Resolution);
}
//Copy the data
if ( !empty($file->Rows) )
{
foreach ($file->Rows->Row as $item)
{
$this->Data[] = array('Id'=>$item->attributes()->Id,'StreetAddress'=>$item->attributes()->StreetAddress,'Place'=>$item->attributes()->Place);
$sql = "insert into tempaddress (id, StreetAddress, Place, PostCode) values ('".$item["Id"]."', '".$item["StreetAddress"]."', '".$item["Place"]."','$SearchTerm')"; CustomQuery($sql);
}}
$result["postcoderesult"]=$postcode;
to use $this-> you have to make class and OOP programming. you don't have any class to use ($this) if you have Key property in a class you have to make a instance from your class with
$OBJ = new class;
and use properties like
$OBJ->Key
$this only use when you have to call methods or properties in class, probably you have a class with Key property and if you have to access this peropery you have ro make instance from your class