Hi, first time caller and after if a little help if possible.
I have created a script that pulls a product feed from my supplier and I am trying to figure out why it does not insert the products into the database.
The script runs with no errors and the final result says it has inserted 1 product into the database but there is nothing in the tables.
Any help would be greatly appreciated.
The database looks like this
> DROP TABLE IF EXISTS `tbl_temp_products`;
> CREATE TABLE IF NOT EXISTS `tbl_temp_products` (
>   `model` varchar(50) NOT NULL,
>   `ean` varchar(99) NOT NULL,
>   `name` varchar(250) NOT NULL,
>   `description` text NOT NULL,
>   `dimension` varchar(50) NOT NULL,
>   `price` varchar(10) NOT NULL,
>   `delivery` varchar(2) NOT NULL,
>   `quantity` varchar(10) NOT NULL,
>   `min_order_qty` varchar(2) NOT NULL,
>   `image_url` varchar(255) NOT NULL,
>   `categories` varchar(255) NOT NULL,
>   `options` varchar(255) NOT NULL
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
and the php as follows
> <?php
> $conn = mysqli_connect("localhost", "root", "", "tbl_temp_products");
> 
> $affectedRow = 0;
> 
> $context  = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
> $url = 'http://www.<supplier-url>.co.uk/gifts/[email protected]&passwd=1234&action=full';
> 
> $xml = file_get_contents($url, false, $context);
> $xml = simplexml_load_string($xml);
> 
> foreach ($xml->children() as $row) {
> 
>     $item = $row->item;
>     $model = $row->model;
>     $ean = $row->ean;
>     $name = $row->name;
>     $description = $row->description;
>     $dimension = $row->dimension;
>     $price = $row->price;
>     $delivery = $row->delivery;
>     $quantity = $row->quantity;
>     $min_order_qty = $row->min_order_qty;
>     $url = $row->url;
>     $image_url = $row->image_url;
>     $categories = $row->categories;
>     $options = $row->options;
> 
>     $sql = "insert into tbl_temp_products(item,model,ean,name,description,dimension,price,delivery,quantity,min_order_qty,url,image_url,categories,options) VALUES ('" . $item . "','" . $model . "','" . $ean . "','" . $name . "','" . $description . "','" . $dimension . "','" . $price . "','" . $delivery . "','" . $quantity . "','" . $min_order_qty . "','" . $url . "','" . $image_url . "','" . $categories . "','" . $options . "')";
> 
>     $result = mysqli_query($conn, $sql);
> 
>     if (! empty($result)) {
>         $affectedRow ++;
>     } else {
>         $error_message = mysqli_error($conn) . "\n";
>     }
> }
> ?>
> <h2>Insert XML Data to MySql Table Output</h2>
> <?php
> if ($affectedRow > 0) {
>     $message = $affectedRow . " records inserted";
> } else {
>     $message = "No records inserted";
> }
> 
> ?>
> <style>
> body {
>     max-width:550px;
>     font-family: Arial;
> }
> .affected-row {
> 	background: #cae4ca;
> 	padding: 10px;
> 	margin-bottom: 20px;
> 	border: #bdd6bd 1px solid;
> 	border-radius: 2px;
>     color: #6e716e;
> }
> .error-message {
>     background: #eac0c0;
>     padding: 10px;
>     margin-bottom: 20px;
>     border: #dab2b2 1px solid;
>     border-radius: 2px;
>     color: #5d5b5b;
> }
> </style>
> 
> <div class="affected-row"><?php  echo $message; ?></div>
> <?php if (! empty($error_message)) { ?>
> <div class="error-message"><?php echo nl2br($error_message); ?></div>
> <?php } ?> 
      
    
