Need a help....my php cannot generate to XML..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kaijencheng
Forum Newbie
Posts: 2
Joined: Tue Apr 12, 2011 12:05 pm

Need a help....my php cannot generate to XML..

Post by kaijencheng »

I am doing a store locate function which I used the google map's code....and it was all fine when I doing everything in the localserver.....
but after I upload it to the 1 and 1.com.......I got some problem here...........I cannot generate my database to XML by my php.....
there is some errors......I guess maybe it's because 1 and 1 server is using php4....and I wrote my php in php5 ( I am not sure)

I've tried add a .htaccess......and put AddType x-mapp-php5 .php on it...
but it just turns out 500 internal error.........
I don't know what to do now? maybe somebody can help me....it would be very appreciated

The code is following...

1 <?php
2
3
4 require("phpsqlsearch_dbinfo.php");
5
6 // Get parameters from URL
7 $center_lat = $_GET["lat"];
8 $center_lng = $_GET["lng"];
9 $radius = $_GET["radius"];
10
11 // Start XML file, create parent node
12 $dom = new DOMDocument("1.0");
13 $node = $dom->createElement("markers");
14 $parnode = $dom->appendChild($node);
15
16 // Opens a connection to a mySQL server
17 $connection=mysql_connect ("db2926.perfora.net", $username, $password);
18 if (!$connection) {
19 die("Not connected : " . mysql_error());
20 }
21
22 // Set the active mySQL database
23 $db_selected = mysql_select_db($database, $connection);
24 if (!$db_selected) {
25 die ("Can\'t use db : " . mysql_error());
26 }
27
28 // Search the rows in the markers table
29 $query = sprintf("SELECT address, store, lat, lng, ( 3959 * acos( cos( radians('37') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('-122') ) + sin( radians('37') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '25' ORDER BY distance LIMIT 0 , 20",
30
31 mysql_real_escape_string($center_lat),
32 mysql_real_escape_string($center_lng),
33 mysql_real_escape_string($center_lat),
34 mysql_real_escape_string($radius));
35 $result = mysql_query($query);
36
37 $result = mysql_query($query);
38 if (!$result) {
39 die("Invalid query: " . mysql_error());
40 }
41
42 header("Content-type: text/xml");
43
44 // Iterate through the rows, adding XML nodes for each
45 while ($row = @mysql_fetch_assoc($result)){
46 $node = $dom->createElement("marker");
47 $newnode = $parnode->appendChild($node);
48 $newnode->setAttribute("store", $row['store']);
49 $newnode->setAttribute("address", $row['address']);
50 $newnode->setAttribute("phone", $row['phone']);
51 $newnode->setAttribute("url", $row['url']);
52 $newnode->setAttribute("lat", $row['lat']);
53 $newnode->setAttribute("lng", $row['lng']);
54 $newnode->setAttribute("distance", $row['distance']);
55 }
56 echo $dom -> save_XML();
57 ?>

but after that I tried it in the browser .....it says....createElement and appendchild are wrong command...therefore I modify all of them to create_element and append_child.......

but after that...it turns

XML Parsing Error: junk after document element
Location: http://iphone.kassienicoledesigns.com/p ... genxml.php
Line Number 2, Column 1:<b>Fatal error</b>: Call to a member function on a non-object in <b>/homepages/26/d233837951/htdocs/iphone/phpsqlsearch_genxml.php</b> on line <b>47</b><br />


I don't know what to do now....stuck in here like almost 1 or 2 days........
should I change my code to php4 ?...or ..make my server to php5?....or....just i have to modify my code in somewhere?......

best regard,
kaijencheng
Forum Newbie
Posts: 2
Joined: Tue Apr 12, 2011 12:05 pm

Re: Need a help....my php cannot generate to XML..

Post by kaijencheng »

I solved this problem by switch to another host server which is running php5......
Post Reply