I've reproduced my code to a prepared statement (I hope correctly enough) and now I'm able to insert values from my XML into my SQL table. The issue is that it only inserts the data from the first product. And I want the statement to execute this for all products.
Here's the lay-out of the online XML that I'm trying to insert:
<?xml version="1.0" encoding="UTF-8"?>
<datafeed>
<info>
<category></category>
<product_count></product_count>
</info>
<programs>
<program>
<program_info>
<name></name>
</program_info>
<products>
<product>
<update_info>
<insert_date></insert_date>
</update_info>
<product_info>
<price></price>
<price_old></price_old>
<ean></ean>
</product_info>
</product>
<product>...</product>
<product>...</product>
<product>...</product>
<product>...</product>
</products>
</program>
</programs>
</datafeed>
The code I'm currently using and that is insert only the values of the first product is:
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
$xml=simplexml_load_file("URL-to-XML") or die("Error: Cannot create object");
foreach ($xml->programs->program->products->product->product_info->price as $price);
foreach ($xml->programs->program->products->product->product_info->price_shipping as $price_shipping);
// prepare and bind
$stmt = $conn->prepare("INSERT INTO BBB (price, price_shipping) VALUES (?,?)");
$stmt->bind_param("ss", $input_price, $input_price_shipping);
// set parameters and execute
$input_price = $price;
$input_price_shipping = $price_shipping;
$stmt->execute();
echo "New records created successfully";
$stmt->close();
$conn->close();
?>
I've tried to reproduce this to a prepared code, so if there's any more information on how to improve my code please let me know.