7 Replies - 1645 Views - Last Post: 21 October 2012 - 03:10 PM

#1 hondakillrsx   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

php file that outputs data from MySql to XML file

Posted 20 October 2012 - 09:17 PM

I'm trying to figure out why this php file will not run. It SUPPOSE to connect to a DB, query all the rows in a DB and then output them to a xml file. I get no connection errors or any error codes period. Just a blank browser screen when I run the php file. Most of this is from the Google.Developers website so I think it may be an issue with my browser or hosting and not the actual code itself.... Help PLEASE!

<?php
require("phpsqlinfo_dbinfo.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",''',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

// 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");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'num_ramps="' . parseToXML($row['num_ramps']) . '" ';
  echo 'craft_lim="' . parseToXML($row['craft_lim']) . '" ';
  echo 'launch_cos="' . parseToXML($row['launch_cos']) . '" ';
  echo 'park_cos="' . parseToXML($row['park_cos']) . '" ';
  echo 'notes="' . parseToXML($row['notes']) . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>



Is This A Good Question/Topic? 0
  • +

Replies To: php file that outputs data from MySql to XML file

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4202
  • View blog
  • Posts: 13,275
  • Joined: 08-June 10

Re: php file that outputs data from MySql to XML file

Posted 21 October 2012 - 01:33 AM

there is an error on line #9
Was This Post Helpful? 0
  • +
  • -

#3 hondakillrsx   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

Re: php file that outputs data from MySql to XML file

Posted 21 October 2012 - 08:10 AM

It actually replaced what the code is when I copied it. It's &#39 , which is being replaced with a "'"(just like it did on this site. I took that line out just in case, for troubleshooting purposes and I still get nothing when I run the php.
Was This Post Helpful? 0
  • +
  • -

#4 hondakillrsx   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

Re: php file that outputs data from MySql to XML file

Posted 21 October 2012 - 08:48 AM

does there need to be any special permissions on the file within the host? Do they need the ability to "execute or write"?
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4202
  • View blog
  • Posts: 13,275
  • Joined: 08-June 10

Re: php file that outputs data from MySql to XML file

Posted 21 October 2012 - 12:09 PM

do you have error reporting/display enabled (usually, an empty document indicates that)?
Was This Post Helpful? 0
  • +
  • -

#6 hondakillrsx   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

Re: php file that outputs data from MySql to XML file

Posted 21 October 2012 - 01:49 PM

I turned it on, this is what I'm getting:

Notice: Use of undefined constant localhost - assumed 'localhost' in /home/lpulcini/public_html/XML_Create.php on line 16

I put quotes around it and now I get nothing, even with error reporting on...
Was This Post Helpful? 0
  • +
  • -

#7 hondakillrsx   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

Re: php file that outputs data from MySql to XML file

Posted 21 October 2012 - 02:42 PM

I tried just a simple php file that echo's below and I get the same blank page
echo '<markers>';


Was This Post Helpful? 0
  • +
  • -

#8 hondakillrsx   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 08-March 12

Re: php file that outputs data from MySql to XML file

Posted 21 October 2012 - 03:10 PM

I got it, I had the header hashed out, it definitely needs to know what type of file it is... Thanks for your help. >.<
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1