Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.