Jump to content

Insert data from Array not inserting rows


Baadier

Recommended Posts

:confused: Ive been trying to insert the data pulled from an xml file. Ive got the xml data stored in an array and ive tried to pull each data set and insert but it fails each time on the first attempt. Inputting plain text works as opposed to using the variables. I think the data has special characters in that are causing mySql to fail. This is the code that im using:

 

$dbhost = 'XXXX';
$dbuser = 'XXXX';
$dbpass = 'XXXX';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

if($conn)
{
echo "Database Connection Successfull...<br /><br />";
}

$dbname = 'a4027212_footy';
mysql_select_db($dbname) or die('Couldnt connect to database table');

if($dbname)
{
echo "Database ".$dbname." Selected..<br /><br />";
}

  $tweetmeme = "http://api.tweetmeme.com/stories/popular.xml?category=sports-soccer&count=30" ; 
  
  $xml = @simplexml_load_file($tweetmeme) or die ("no file loaded") ; 
  if($xml)
  {
echo "Tweetmeme XML loaded with ".count($xml->stories->story)." stories in the file..<br /><br />";
  }
if(get_magic_quotes_gpc())
{
echo "Magic Quotes is ON<br /><br />";
}
foreach($xml->stories->story as $story)
{
$title=$story->title;
$url=$story->url;
$media_type=$story->media_type;
$created=$story->created_at;
//$current_time=$date();
$url_count=$story->url_count;
$comment_count=$story->comment_count;
$excerpt=$story->excerpt;


$sql = "INSERT INTO ft_tweets (title,url,media_type,created_at,mention_count,comment_count,excerpt) VALUES ($title,$url,$media_type,$created,$url_count,$comment_count,$excerpt)";



$result = mysql_query($sql) or die(mysql_error());
if($result)
{
	echo "added to database<br />";
}
}
echo "<br /><br />";

 

ERROR MESSAGES:

Database Connection Successfull...

 

Database a4027212_footy Selected..

 

Tweetmeme XML loaded with 30 stories in the file..

 

Magic Quotes is ON

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'injury news ahead of Bolton game | News Archive | News | Arsenal.com),http://www' at line 1

 

PHP version:  5.2.* | MySQL version:  5.0.81-community

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.