...

View Full Version : Resolved inserting xml values into databse



LJackson
04-06-2009, 12:19 AM
Hi

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


$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

LJackson
04-06-2009, 01:24 PM
ok i have sorted this no thanks i used the

mysql_real_escape_string

and that worked :)

cheers



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum