I've made this code; but all i get are empty fields in the database. The connection with the db is working. I can print the XML file on my screen : object(SimpleXMLElement)#2 (3) { ["item"]=> string(4) "Tove" ["product_category_code"]=> string(4) "Jani" ["SKU"]=> string(8) "Reminder" } ToveJaniReminderwaarden
I don't get a message 'recoreds inserted' or 'no records inserted'. But the moment i put it in my query to insert it in the database; the fields stay empty. Why?
check the connection with the database echo the variables use AI (says the code is ok) insert with a textfield (gets inserted)
//check if xml exists -- good. 
  if (file_exists('note.xml')) {
      
 // If XML file exists then load the XML file --  good 
$xml_file = simplexml_load_file('note.xml');
 
// Display the content of XML file -- gets displayed 
     var_dump($xml_file);   
   } 
   else {
     exit('Fail to open the file');}
  $xml = simplexml_load_file("note.xml")
  or die("Error: Cannot create object");
// Assign values --> ?? 
foreach ($xml->children() as $row) {
  $item = $row->item;
  $product_category_code = $row->product_category_code;
  $SKU = $row->SKU;  
  //echo -> gets echo'ed
  echo $xml->item; 
  echo $xml->product_category_code;
  echo $xml->SKU; 
  //check again and print -- .yep.  
  echo ($item . $product_category_code . $SKU . "waarden"); 
  // SQL query to insert data into xml table
  $sql = $con->prepare("INSERT INTO Producten (product_category_code, SKU, item) VALUES (product_category_code, item , SKU)");
  $sql->bind_param("sss", $product_category_code, $SKU, $item);
  $sql->execute(); 
  if ($sql->affected_rows > 0) {
    $affectedRow ++;
  } else {
    $error_message = $con->error . "
";
  }
}
if ($affectedRow > 0) {
  $message = $affectedRow . " records inserted";
} else {
  $message = "No records inserted";
}
