Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation inserting xml values into databse

    Hi

    i have the following code to insert the values of a feed into a database table

    PHP Code:
     $xml=("http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&TD_PARAM=http://clkuk.tradedoubler.com/click?p=23708&a=1515427&url=");


    $xmlDoc = new DOMDocument();
    $xmlDoc->load($xml);

    for (
    $i 0$i 10$i++) {
    //get elements from "<channel>"
    $channel=$xmlDoc->getElementsByTagName('entry')->item($i);
    $channel_title $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
    $channel_image str_replace("30x30-50","100x100-75",$channel->getElementsByTagName('image')->item(0)->childNodes->item(0)->nodeValue);
    $channel_link $channel->getElementsByTagName('id')->item(0)->childNodes->item(0)->nodeValue;
    $channel_album $channel->getElementsByTagName('name')->item(0)->childNodes->item(0)->nodeValue;
    $channel_artist $channel->getElementsByTagName('artist')->item(0)->childNodes->item(0)->nodeValue;
    $channel_cost $channel->getElementsByTagName('price')->item(0)->childNodes->item(0)->nodeValue;
    //output elements from "<channel>"
    $sql "INSERT INTO product_database (pID, store, storeLink, productTitle, productLink, productIMG, description, price) VALUES ($i, 'itunes', '$channel_link', '$channel_artist - $channel_album', '$channel_link', '$channel_image', 'description here', '$channel_cost')";
    $query mysql_query($sql);

    echo (
    "<a href='$channel_link'>".$channel_title."</a>");
    echo(
    "<br />");
    echo 
    $channel_album;
    echo(
    "<br />");
    echo 
    $channel_artist;
    echo(
    "<br />");
    echo 
    $channel_cost;
    echo(
    "<br />");
    echo (
    "<img src='$channel_image'>");
    echo(
    "<br />");

    the problem im having is if the $channel_title has a ' in it e.g "don't run" it wont insert any of that record because i assume its running into problems with inserting 'don't run' so there are now 3 single quotes for this string.

    how do i get around this?
    cheers all
    Luke
    Last edited by LJackson; 04-06-2009 at 12:24 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok i have sorted this no thanks i used the

    mysql_real_escape_string

    and that worked

    cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •