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

  • SEARCH
  • Home
  • 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 7087255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:39:06+00:00 2026-05-28T07:39:06+00:00

I am using mysql_real_escape_string function while inserting the data into MySQL database. I am

  • 0

I am using mysql_real_escape_string function while inserting the data into MySQL database. I am getting

“End tag ‘test_field’ does not match the start tag ‘End’. Error
processing resource”

while generating the XML. It looks like special characters or less than or greater than symbols causing this problem. Here is my code. Please let me know if there are any suggestions.

Here is PHP code.

$result = mysql_query("SELECT * from table1");

header("Content-Type: application/xml");
echo sqlToXml($result, "SalesOrder", "sales");

function sqlToXml($queryResult, $rootElementName, $childElementName)
{

$xmlData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; 
$xmlData .= "<" . $rootElementName . ">";

while($record = mysql_fetch_object($queryResult))
{ 
    $xmlData .= "<" . $childElementName . ">";
    for ($i = 0; $i < mysql_num_fields($queryResult); $i++)
    { 
        $fieldName = mysql_field_name($queryResult, $i); 
        $xmlData .= "<" . $fieldName . ">";
        if(!empty($record->$fieldName))
            $xmlData .= $record->$fieldName; 
        else
            $xmlData .= "null"; 

        $xmlData .= "</" . $fieldName . ">"; 
    } 

        $detail = mysql_query("SELECT * from table2 WHERE salesordernumber = '".$record->SalesOrderNumber."'");
while ($row = mysql_fetch_object($detail)) { 
   $xmlData .= "<Details>";
   $xmlData .= "<SalesOrderDetailID>" . $row->SalesOrderDetailID . "</SalesOrderDetailID>";
   $xmlData .= "<Name>" . $row->Name . "</Name>";
   $xmlData .= "<CarrierTrackingNumber>" . $row->CarrierTrackingNumber . "</CarrierTrackingNumber>";
   $xmlData .= "</Details>";
}



    $xmlData .= "</" . $childElementName . ">"; 
} 
$xmlData .= "</" . $rootElementName . ">"; 
}
  • 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-28T07:39:07+00:00Added an answer on May 28, 2026 at 7:39 am

    I’d suggest using PHPs XMLWriter for generating the XML. You can easily generate valid XML-files with it and imo it is much more readable:

    function sqlToXml($queryResult, $rootElementName, $childElementName) {
        $w = new XMLWriter();
        $w->openMemory();
        $w->setIndent(true);
        // use tabs as indents
        $w->setIndentString("   ");
        $w->startDocument("1.0", 'ISO-8859-1');
        $w->startElement($rootElementName);
    
        while($record = mysql_fetch_object($queryResult)) {
            $w->startElement($childElementName);
            for ($i = 0; $i < mysql_num_fields($queryResult); $i++) { 
                $fieldName = mysql_field_name($queryResult, $i); 
                $w->startElement($fieldName);
                if(!empty($record->$fieldName)) {
                    $w->writeCData($record->$fieldName);
                }
                else {
                    $w->writeCData("null");
                }
                $w->endElement(); // $fieldName
            } 
            $w->endElement(); // $childElementName
        } 
        $w->endElement(); // $rootElementName
        $w->endDocument();
        return $w->outputMemory();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following
I saved some data in the database using mysql_real_escape_string() so the single quotes are
I'm tryin to insert dates using the date function while inserting posts. When the
i created a simple search engine that displays mysql database results using the php
Im getting this error when Im trying to update data in the database. this
Is there an SQL injection possibility even when using mysql_real_escape_string() function? Consider this sample
I am submitting a form to my MySQL database using PHP. I am sending
I'm using following function to import the csv file into db. All is working
I am using Json to retrieve elements from mysql and insert them into form
How come I can't get mysql_real_escape_string to work when using PDO? I keep getting

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.