Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3611746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:54:49+00:00 2026-05-18T21:54:49+00:00

I have written a PHP script to write an XML document but there is

  • 0

I have written a PHP script to write an XML document but there is an error:

 <?php
$db = "unadb";
$connection = mysql_connect("localhost", "root", "") or die("Could not connect.");
$table_name = 'article';

$db = mysql_select_db($db, $connection);
$query = "select * from " . $table_name;
$result = mysql_query($query, $connection) or die("Could not complete database query");
$num = mysql_num_rows($result);
if ($num != 0) {
 $file= fopen("results.xml", "w");
 $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
 $_xml .="<atricle>";

 while ($row = mysql_fetch_array($result)) {
      $_xml .="\t<page>\r\n";
 if ($row["title"]) {
     $_xml .="\t<page title=\"" . $row["title"] . "\">\r\n";
     $_xml .="\t<source>" . $row["source"] . "</source>\r\n";
     $_xml .="\t<kw>" . $row["kw"] . "</kw>\r\n";
     $_xml .="\t\t<Url>" . $row["url"] . "</Url>\r\n";
     $_xml .="\t\t<author>" . $row["author"] . "</author>\r\n";
     $_xml .="\t<status>" . $row["status"] . "</status>\r\n";
     $_xml .="\t</page>\r\n";
 } else {
 $_xml .="\t<page title=\"Nothing Returned\">\r\n";
 $_xml .="\t\t<file>none</file>\r\n";
 $_xml .="\t</page>\r\n";
 } }
 $_xml .="</atricle>";

 fwrite($file, $_xml);
 fclose($file);

 echo "XML has been written.  <a href=\"results.xml\">View the XML.</a>";
 } else {
 echo "No Records found";

 } ?>

The output is:

<?xml version="1.0" encoding="UTF-8" ?>
<atricle>   <page>
    <page title="Coming Race">
    <source>http://www.public-domain-content.com/books/Coming_Race/C1P1.shtml</source>
    <kw>home</kw>
        <Url>http://www.uberarticles.com/articles/artsubmit/upreview.php?article_id=580332</Url>
        <author>afnan</author>
    <status>active</status>
    </page>
    <page>
    <page title="Coming Race">
    <source>http://www.public-domain-content.com/books/Coming_Race/C1P1.shtml</source>
    <kw>home</kw>
        <Url>http://www.uberarticles.com/articles/artsubmit/upreview.php?article_id=580332</Url>
        <author>Doctor</author>
    <status>active</status>
    </page>
</atricle>

I think the XML is OK but there is an error:

error on line 18 at column 11: Opening and ending tag mismatch: page line 0 and atricle

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:54:50+00:00Added an answer on May 18, 2026 at 9:54 pm

    You’re creating XML with raw string manipulation. Getting the open and close tags to match (you have two open <page> tags for each close </page> is going to be the first of many problems with escaping the SQL results you’re dumping straight into the XML.

    Use a library, or you will have to do a very large amount of work to fix lots of corner cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to download some files. I have written a php script that
For our online game, we have written tons of PHP classes and functions grouped
I have written a web app in PHP which makes use of Ajax requests
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have a code snippet written in PHP that pulls a block of text
I have some old apps written in PHP that I'm thinking of converting to
I have a prototype website written in PHP. Lately i've rewritten code to separate
I have some code I've written in PHP for consuming our simple webservice, which
I have a small AJAX application, written in PHP that I did not secure
I have inherited some legacy PHP code what was written back when it was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.