-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.

7
  • have you tried anything ?? Commented May 9, 2017 at 9:41
  • have you tried ? please show your code Commented May 9, 2017 at 9:44
  • possible duplicate : stackoverflow.com/questions/2161722/… Commented May 9, 2017 at 9:44
  • stackoverflow.com/questions/29057366/… Commented May 9, 2017 at 9: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 [stackoverflow.com/help]. Commented May 9, 2017 at 9:46

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.