Hello,
I’m getting a error i’ve not seen before, which is: [B]Call to a member function createElement() on a non-object
This is my php code, It creates a xml document to feed marker info to a google maps api:
[code=php]
<?php
// Start XML file, create parent node
$dom = new DOMDocument(“1.0”);
$node = $dom->createElement(“markers”);
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$dbcnx = @mysql_connect(‘xxxxxx’, ‘xxxxxx’, ‘xxxxxx’);
if (!$dbcnx) {
exit(‘<p>Unable to connect to the ‘ .
‘database server at this time.</p>’);
}
if (!@mysql_select_db(‘xxxxxx’)) {
exit(‘<p>Unable to locate the ‘ .
‘database at this time.</p>’);
}
//local search function
if(isset($_GET[‘postcode’]))
{
$postcode_initial = mysql_real_escape_string($_GET[‘postcode’]);
$postcode = trim($postcode_initial);
getDistanceUK_ssc($postcode,100);
}
function getDistanceUK_ssc($postcode,$area)
{
// database query to find postcodes withinh x ($area) distance from submitted postcode
$query = “SELECT postcode1, postcode2, postcode, name, address1, address2, address3, address4, tel, email, website, lat, lng, typ, (SQRT(POW((b.x – a.x), 2) + POW((b.y – a.y), 2))/1000) * 0.621 AS distance
FROM postcodes a, postcodes b, dealers
WHERE typ=’standard’
AND a.outcode LIKE ‘”.$postcode.”‘ AND b.outcode = dealers.postcode1
HAVING (distance < ‘”.$area.”‘)
ORDER BY distance asc LIMIT 10″;
$result = mysql_query($query);
//start the xml
header(“Content-type: text/xml”);
while ($row = @mysql_fetch_assoc($result))
{
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement(“marker”);
$newnode = $parnode->appendChild($node);
$newnode->setAttribute(“name”, $row[‘name’]);
$newnode->setAttribute(“address1”, ucfirst(strtolower($row[‘address1’])));
$newnode->setAttribute(“address2”, ucfirst(strtolower($row[‘address2’])));
$newnode->setAttribute(“address3”, ucfirst(strtolower($row[‘address3’])));
$newnode->setAttribute(“address4”, ucfirst(strtolower($row[‘address4’])));
$newnode->setAttribute(“postcode”, ucfirst(strtolower($row[‘postcode’])));
$newnode->setAttribute(“tel”, ucfirst(strtolower($row[‘tel’])));
$newnode->setAttribute(“fax”, ucfirst(strtolower($row[‘fax’])));
$newnode->setAttribute(“email”, ucfirst(strtolower($row[’email’])));
$newnode->setAttribute(“lat”, $row[‘lat’]);
$newnode->setAttribute(“lng”, $row[‘lng’]);
$newnode->setAttribute(“typ”, $row[‘typ’]);
//add more fields here
}
// if no results are found display message
//$count=mysql_num_rows($result);
//if($count==0)
//{
//no dealers
//}
}
echo $dom->saveXML();
?>
(I’ve blanked out the database connections)
This was working fine until i added the local search query, does anyone have any idea what is causing the error?
Thanks