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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:40:09+00:00 2026-05-26T10:40:09+00:00

I wonder whether someone can help me please. I’m trying to put together a

  • 0

I wonder whether someone can help me please.

I’m trying to put together a PHP script that takes data from an xml file and places the data in a mySQL data. I’ve been working on this for a few days and I’m still can’t seem to get this right.

This is the code that I’ve managed to put together:

    <? 

      $objDOM = new DOMDocument(); 
      $objDOM->load("xmlfile.xml"); 

      $Details = $objDOM->getElementsByTagName("Details"); 

      foreach( $Details as $value ) 
      { 

        $listentry = $value->getElementsByTagName("listentry"); 
        $listentrys  = $listentry->item(0)->nodeValue;

        $sitetype = $value->getElementsByTagName("sitetype"); 
        $sitetypes  = $sitetype->item(0)->nodeValue;

        $sitedescription = $value->getElementsByTagName("sitedescription"); 
        $sitedescriptions  = $sitedescription->item(0)->nodeValue;

        $siteosgb36lat = $value->getElementsByTagName("siteosgb36lat"); 
        $siteosgb36lats  = $siteosgb36lat->item(0)->nodeValue;

        $siteosgb36lon = $value->getElementsByTagName("siteosgb36lon"); 
        $siteosgb36lons  = $siteosgb36lon->item(0)->nodeValue;

        //echo "$listentrys :: $sitetypes :: $sitedescriptions :: $siteosgb36lats ::         $siteosgb36lons <br>"; 


      } 

    require("phpfile.php");

    //Opens a connection to a MySQL server
    $connection = mysql_connect ("hostname", $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());
    }

   mysql_query("INSERT IGNORE INTO scheduledsites (listentry, sitetype, sitedescription, siteosgb36lat, siteosgb36lon) VALUES('$listentrys','$sitetypes','$sitedescriptions','$siteosgb36lats','$siteosgb36lons') ")  
or die(mysql_error());  


    echo "Data Inserted!"; 


?>

I can pull the data from the xml file, but it’s the part of the script that sends the data to my database table that I’m having trouble with.

The script runs but only the last record is saved to the database.

I can parse the fields from the xml file without any problems and the check I’m trying to put in place is, if there is a ‘listentry’ number in the new data that is matched to one already in the table then I don’t want that record to be added to the table, i.e. ignore it.

I just wondered whether someone could perhaps take a look at this please and let me know where I’m going wrong.

Many thanks

  • 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-26T10:40:09+00:00Added an answer on May 26, 2026 at 10:40 am

    You are only calling mysql_query once. So it will only insert one row.

    The sql needs to be inside the loop.

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

Sidebar

Related Questions

I wonder whether someone can help please. I'm trying to put together a script
I wonder whether someone can help me please. I'm trying to put together a
I wonder whether someone can help me please. I'm trying to put together a
I wonder whether someone can help me please. I've put together this page, which
I wonder whether someone could help me please. I'm trying to put together an
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone can help me please. I'm using the following script to
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help please. I'm trying to put
I wonder whether someone may be able to help me please. I'm trying to

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.