tags:

views:

25

answers:

1

Im putting together a simple script that pulls content from the tweetmeme api and then inserts it into a database for further formating. This is what i currently have but it inserts no records and returns no errors for the database connection so i can assume it connects and fails at the insertion.

   $dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '****';

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

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



  $tweetmeme = "http://api.tweetmeme.com/stories/popular.xml?category=sports-soccer&count=30" ; 

  $xml = @simplexml_load_file($tweetmeme) or die ("no file loaded") ; 

 echo count($xml->stories->story)."stories in the XML file<br /><br />";
echo $xml->getName() . "<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);

doing a vardump() on the various items returns "object(SimpleXMLElement)" and this is what the xml structure looks like for an example link text

A: 

Make sure your query goes successful, try adding or mysql_error() like this to see if there is any error coming up:

$result = mysql_query($sql) or die(mysql_error());
Sarfraz
mysql_error reports "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"
Baadier
sorry enter sends the post.. The error message finishes off with the first item being inserted so it fails immedietely
Baadier
heres the table structure from the database if that helps: `ft_tweets` ( `id` int(11) NOT NULL auto_increment, `title` text character set utf8 collate utf8_unicode_ci NOT NULL, `url` text character set utf8 collate utf8_unicode_ci NOT NULL, `media_type` set('news','video','image') character set utf8 collate utf8_unicode_ci NOT NULL, `created_at` date NOT NULL, `added_at` date NOT NULL, `mention_count` smallint(6) NOT NULL, `comment_count` smallint(6) NOT NULL, `excerpt` text character set utf8 collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`))
Baadier