I've been trying to find the answer to the following question, but can't seem to find the solution. I've been able to insert one product price in my SQL table, but all the possibilities I try for multiple products aren't working. This is my working code for one product.
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$xml=simplexml_load_file("URL") or die("Error: Cannot create object");
foreach ($xml->product as $row) {
$price = $row -> price;
$sql = "INSERT INTO `tablename` (`price`)
VALUES ('$price')";
}
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
</body>
</html>
What should I add or change to make the query go through the whole XML file and look for all the prices of the products?
Thanks in advance!