Updating MySQL Using XML?

Discussion in 'PHP' started by DmitryS, Feb 28, 2011.

  1. #1
    Hi,

    Apologies to keep going on about this but I have hit a brick wall over updating my database with XML. I have spent around 100 hours on this and so far I can only copy the file, I am unable so far to update my database with the information from the XML file. I would be very grateful for any help you can offer to fix this.

    $id = $prod->prod['id'];
    $description = $prod->name;
    $image = $prod->awImage;
    $fulldescription = $prod->desc;
    
    //insert query
    if(strlen($prod) > 0)
    
    {
    $query = mysql_query("REPLACE INTO productfeed
    (id, description, fulldescription, image)
    VALUES ('$id','$description','$image','$fulldescription') ");
    echo $id . "has been inserted </br>";
    }
    else{echo ("This does not work </br>");}
    }
    Code (markup):
    This is an outline of the XML feed I am using, it only includes one item which I am using as a test:
    - <uri lang="EN">
      <awTrack>http://www.awin1.com/pclick.php?p=39920873&a=98057&m=1829</awTrack> 
      <awImage>http://images.productserve.com/preview/1829/39920873.jpg</awImage> 
      <mLink>http://www.pinesolutions.co.uk/bedroom-furniture/mirrors/wall-mirrors/oakleigh-wall-mirror-60x90/</mLink> 
      <mImage>http://media.pinesolutions.co.uk/images/products/903.333.3.4.jpg</mImage> 
      </uri>
    - <price curr="GBP">
      <buynow>40.00</buynow> 
      </price>
    - <cat>
      <awCatId>424</awCatId> 
      </cat>
      <brand /> 
      </prod>
      </merchant>
    Code (markup):
     
    DmitryS, Feb 28, 2011 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    
    $id = $prod->prod['id'];
    $description = $prod->name;
    $image = $prod->awImage;
    $fulldescription = $prod->desc;
    
    //insert query
    if(strlen($prod) > 0)
    
    {
    $query = mysql_query("UPDATE productfeed SET description = '$description', fulldescription = '$fulldescription', image = '$image' WHERE id = '$id'") or die(mysql_error());
    if(mysql_affected_rows() == 1)
      echo $id . "has been inserted </br>";
    } else{
    echo "This does not work </br>";
    }
    }
    
    PHP:
     
    tvoodoo, Feb 28, 2011 IP