niche Posted May 10, 2012 Share Posted May 10, 2012 (edited) I'm trying to use this script from: https://developers.g...cles/phpsqlajax Google calls this script: phpsqlajax_genxml.php I've checked the php_domxml extension and restarted my wampserver. I'm running php 5.2.9-2. I've defined $username, $password, and $database per instructions in a script called phpsqlajax_dbinfo.php. It's causing errors. Do you know what's causing these problems? Warning: domnode::append_child() expects parameter 1 to be object, null given in E:\wamp\www\phpsqlajax_genxml.php on line 7 Notice: Use of undefined constant localhost - assumed 'localhost' in E:\wamp\www\phpsqlajax_genxml.php on line 10 Notice: Undefined variable: username in E:\wamp\www\phpsqlajax_genxml.php on line 10 Notice: Undefined variable: password in E:\wamp\www\phpsqlajax_genxml.php on line 10 Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\phpsqlajax_genxml.php on line 10 Not connected : Access denied for user 'ODBC'@'localhost' (using password: NO) The script: <?phprequire("phpsqlajax_dbinfo.php"); // Start XML file, create parent node$doc = domxml_new_doc("1.0");$node = $doc->create_element("markers");$parnode = $doc->append_child($node);// Opens a connection to a mySQL server$connection=mysql_connect ("localhost", $username, $password);if (!$connection) { die('Not connected : ' . mysql_error());}// Set the active mySQL database$db_selected = mysql_select_db($database, $connection);if (!$db_selected) { die ('Can't use db : ' . mysql_error());}// Select all the rows in the markers table$query = "SELECT * FROM markers WHERE 1";$result = mysql_query($query);if (!$result) { die('Invalid query: ' . mysql_error());}header("Content-type: text/xml");// Iterate through the rows, adding XML nodes for eachwhile ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $doc->create_element("marker"); $newnode = $parnode->append_child($node); $newnode->set_attribute("name", $row['name']); $newnode->set_attribute("address", $row['address']); $newnode->set_attribute("lat", $row['lat']); $newnode->set_attribute("lng", $row['lng']); $newnode->set_attribute("type", $row['type']);}$xmlfile = $doc->dump_mem();echo $xmlfile;?> Edited May 10, 2012 by niche Link to comment Share on other sites More sharing options...
niche Posted May 10, 2012 Author Share Posted May 10, 2012 Apparently the original script is for PHP4 according to: http://stackoverflow.com/questions/2467448/using-php-mysql-with-google-maps Here's the php5 version, but it still produces this error : any ideas? Fatal error: Call to undefined function DOMDocument() in E:\wamp\www\phpsqlajax_genxml.php on line 6 I changed line 6 from $doc = new DOMDocument("1.0"); to $doc = DOMDocument("1.0"); I couldn't find new DOMDocument in the manual. PHP5 version: <?phprequire("phpsqlajax_dbinfo.php");// Start XML file, create parent node$doc = new DOMDocument("1.0");$node = $doc->createElement("markers");$parnode = $doc->appendChild($node);// Opens a connection to a mySQL server$connection=mysql_connect ('localhost', $username, $password);if (!$connection) { die('Not connected : ' . mysql_error());}// Set the active mySQL database$db_selected = mysql_select_db($database, $connection);if (!$db_selected) { die ('Can\'t use db : ' . mysql_error());}// Select all the rows in the markers table$query = "SELECT * FROM markers WHERE 1";$result = mysql_query($query);if (!$result) { die('Invalid query: ' . mysql_error());}header("Content-type: text/xml");// Iterate through the rows, adding XML nodes for eachwhile ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE $node = $doc->createElement("marker"); $newnode = $parnode->appendChild($node); $newnode->set_attribute("name", $row['name']); $newnode->set_attribute("address", $row['address']); $newnode->set_attribute("lat", $row['lat']); $newnode->set_attribute("lng", $row['lng']); $newnode->set_attribute("type", $row['type']);}echo $doc->saveXML();?> Link to comment Share on other sites More sharing options...
niche Posted May 10, 2012 Author Share Posted May 10, 2012 Line 6 should be: $doc = new DOMDocument("1.0");instead of: $doc = DOMDocument("1.0");according to: http://php.net/manual/en/domdocument.construct.phpThe error messages now are:Warning: domdocument::domdocument() [domdocument.domdocument]: Entity: line 1: parser error : Start tag expected, '<' not found in E:\wamp\www\phpsqlajax_genxml.php on line 6Warning: domdocument::domdocument() [domdocument.domdocument]: 1.0 in E:\wamp\www\phpsqlajax_genxml.php on line 6Warning: domdocument::domdocument() [domdocument.domdocument]: ^ in E:\wamp\www\phpsqlajax_genxml.php on line 6Fatal error: Call to undefined method domdocument::createElement() in E:\wamp\www\phpsqlajax_genxml.php on line 7 Link to comment Share on other sites More sharing options...
niche Posted May 10, 2012 Author Share Posted May 10, 2012 (edited) I found that I can dynamically edit the google iframe with my own code and by pass all the disfunctional google code. You get the iframe from the link button on a google map. It will look like this: <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=7327+S+30th+St,+Lincoln,+NE&aq=&sll=40.810476,-96.678362&sspn=0.008819,0.020041&ie=UTF8&hq=&hnear=7327+S+30th+St,+Lincoln,+Nebraska+68516&ll=40.737174,-96.675671&spn=0.008828,0.020041&t=m&z=14&iwloc=A&output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=7327+S+30th+St,+Lincoln,+NE&aq=&sll=40.810476,-96.678362&sspn=0.008819,0.020041&ie=UTF8&hq=&hnear=7327+S+30th+St,+Lincoln,+Nebraska+68516&ll=40.737174,-96.675671&spn=0.008828,0.020041&t=m&z=14&iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small> You can make it dynamic like this: <?php$hn = "7327";$dir = "S";$sn = "30th";$stype = "St";$city = "Lincoln";$st = "Nebraska";$zip = "68516";$locationString = "$hn,+$dir,+$sn,+$stype,+$city,+$st,+$zip"; ?><iframe width="225" height="150" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?q=4<?php echo $locationString; ?>&oe=utf-8&client=firefox-a&ie=UTF8&hq=&hnear=<?php echo $locationString; ?>&ll=&spn=0.008827,0.020041&t=m&z=14&output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?q=<?php echo $locationString; ?>&oe=utf-8&client=firefox-a&ie=UTF8&hq=&hnear=<?php echo $locationString; ?>&ll=&spn=0.008827,0.020041&t=m&z=14&source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small> Google sucked 6 hours out of my life playing with their tutorial. Altering their iframe took about 20 min. Obviously, I still have to connect it with a table. Time to hit the rack. Edited May 10, 2012 by niche Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now