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 8620427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:34:38+00:00 2026-06-12T06:34:38+00:00

I have a php script which… Deletes a record from a MySql table (based

  • 0

I have a php script which…

  1. Deletes a record from a MySql table (based on the id) via PDO
  2. Get’s an updated list of all the records in that table, then…
  3. Spits out the list as XML (via DomDocument)

The Problem is that when I run the script I see the following error message when I check the XHR tab for XML:

XML Parsing Error: XML or text declaration not at start of entity Location: moz-nullprincipal:{45b1a3cb-ef07-42c9-b4bd-b15ba996fb4c} Line Number 3, Column 1:

^

When looking at the Response section of the XHR tab in Firebug, I noticed that the xml starts below the top of the page. On the third row to be exact.

So… I made the call directly from a browser including the id of a record to be deleted
( i.e. http://mylocalsite.dev/ajax-delete-post-v02.php?dlt=40 )

Wherein I then got (pretty much the same error (this time in the browser):

XML Parsing Error: XML or text declaration not at start of entity
Location: http://mylocalsite.dev/ajax-delete-post-v02.php?dlt=40
Line Number 3, Column 1:
^

Below is the code I’m using: (note that if I simply take out the call to the db, it works. So I am assuming that something I am doing is creating the extra spaces, but dang if I can find it).

<?php 
$doc = new DOMDocument('1.0','utf-8');
$posts = $doc->createElement('posts');
$doc->appendChild($posts);

// dynamically generate posts

    // set DB connection vars
    $hostname = "localhost";
    $database = "somedb";
    $username = "someuser";
    $password = "somepassword";
    $hostinfo = "mysql:host=$hostname;dbname=$database";
    
    // connect to db
    try
    {
        // Create the database handler
        $dbh = new PDO($hostinfo,$username, $password);

        // Set the error reporting attributes 
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    
        // Create the sql string
        $sql_select = 'SELECT * FROM posts ORDER BY date_start DESC';   
        
        // prepare the SQL statement 
        $stmt = $dbh->query($sql_select);
        
        while($row = $stmt->fetch())
        {
            $post = $doc->createElement('post');
            $post->setAttribute('id',$row['id']);
            $p_text = $doc->createElement('text',htmlentities($row['text']));
            $p_date_start   = $doc->createElement('date_start',$row['date_start']);
            $p_date_end     = $doc->createElement('date_end',$row['date_end']);
            $p_details_link = $doc->createElement('details_link',htmlentities($row['details_link']));   

            $posts->appendChild($post);
            $post->appendChild($p_text);
            $post->appendChild($p_date_start);
            $post->appendChild($p_date_end);
            $post->appendChild($p_details_link);
        }

        // Close the db connection
        $dbh = null;
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }

// for some reason this is writing it out starting on the third line???
echo $doc->saveXML(); 
?>

I don’t get. By the way, did I mention that I’m a greenhorn?

🙂

thanks
sleeper

  • 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-06-12T06:34:40+00:00Added an answer on June 12, 2026 at 6:34 am

    I found it. It WAS a space. Brought on by seperate tags for FirePHP. Removed them and whalla!

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

Sidebar

Related Questions

I have created a PHP script which builds a table from an XML document
I have a PHP script which selects a code from an InnoDB table and
I have PHP scrapping script which fetches HTML table content from another website. The
I have a php script which queries a list of clients from a mysql
I have a PHP script which fetches data from Salesforce via the Salesforce API
I have a php script which is editing records in mysql table. I have
I have this PHP script which i'm grabbing images from a directory and displaying
Here I have a simple php script which displays some values from a database
I have a php script which takes a relative pathname via $_GET , reads
I have a PHP script which calls methods from a class I have written.

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.