View Full Version : Resolved inserting xml values into databse

04-05-2009, 11:19 PM

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


$xmlDoc = new DOMDocument();

for ($i = 0; $i < 10; $i++) {
//get elements from "<channel>"
$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

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


and that worked :)


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum