-2

I am trying to Insert data from XML to MySql.

So far i have written this: ?php

$servername = "localhost";
$username = "root";
$password = "rootuser";
$dbname = "my_data";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}


$string = file_get_contents('rss.xml');
$xml = new SimpleXMLElement($string);

echo 'All Values of a Group: -';
foreach($xml->system->system as $item){
    echo $item->MY_Name.' - ';
    echo $item->Version.' - ';
    echo '<br/>';
    mysqli_query($conn, "INSERT INTO customer_data_table (My_Name, Version ) VALUES (". $item->My_Name.", '". $item->Version."')" );
}
?

Any help is appreciated.

mynexsus
  • 17
  • 3
  • have you tried anything ?? – Prashant Srivastav May 09 '17 at 09:41
  • have you tried ? please show your code – Shafiqul Islam May 09 '17 at 09:44
  • possible duplicate : http://stackoverflow.com/questions/2161722/parsing-xml-data-using-php-to-put-into-mysql-database – Ahmed Ginani May 09 '17 at 09:44
  • http://stackoverflow.com/questions/29057366/insert-xml-data-to-mysql-table-using-php – Shafiqul Islam May 09 '17 at 09:45
  • 1
    It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you’ve written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [https://stackoverflow.com/help]. – airos May 09 '17 at 09:46
  • Possible duplicate of [Parsing XML data using php to put into mysql database](http://stackoverflow.com/questions/2161722/parsing-xml-data-using-php-to-put-into-mysql-database) – airos May 09 '17 at 09:47
  • Code added. Can you please check – mynexsus May 09 '17 at 12:20

1 Answers1

0

In PHP use xml parser to get the values from the XML. Here is the code

$xml = '<system>
<Name>new</Name>
<Month>Feb</Month>
</system>';
echo "<pre>";
print_r(new SimpleXMLElement($xml));

Here you can get all the values from XML tag and you can insert into Database.

Hari
  • 44
  • 9