maxitis92 / rssingest

Automatically exported from code.google.com/p/rssingest
0 stars 0 forks source link

Data not inserting in DB #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am not a programmer, however i have followed your instruction. Am getting the 
following displayed on the IE page & the data is not getting imported. I am 
using the constructed URL as recommended by you. THere is No error on the 
server logs.

*/ //require_once("dbCon/dbcon.php"); $db_hostname="localhost"; 
$db_username="spiderco_stanley"; $db_password="network21"; 
$private_access_key="1621"; // Check a few bits and pieces 
if(isset($_GET['feed_url'])) { $feed_url = $_GET['feed_url']; } else { 
die("Need to pass the (consistent) 'feed url'"); } 
if(isset($_GET['access_key'])) { if($_GET['access_key']==$private_access_key) { 
echo "Access key correct, proceeding...

"; } else { die("wrong access key"); } } else { die("Need to pass the 
'access_key' URL parameter"); } try { /* query the database */ // $db = 
getCon(); $db = mysql_connect($db_hostname,$db_username,$db_password); if 
(!$db) { die("Could not connect: " . mysql_error()); } 
mysql_select_db("spiderco_rss", $db); echo "Starting to work with feed URL '" . 
$feed_url . "'"; /* Parse XML from http://feeds.bbci.co.uk/news/rss.xml */ 
//$RSS_DOC = simpleXML_load_file('http://feeds.bbci.co.uk/news/rss.xml'); 
libxml_use_internal_errors(true); $RSS_DOC = simpleXML_load_file($feed_url); if 
(!$RSS_DOC) { echo "Failed loading XML\n"; foreach(libxml_get_errors() as 
$error) { echo "\t", $error->message; } } /* Get title, link, managing editor, 
and copyright from the document */ $rss_title = $RSS_DOC->channel->title; 
$rss_link = $RSS_DOC->channel->link; $rss_editor = 
$RSS_DOC->channel->managingEditor; $rss_copyright = 
$RSS_DOC->channel->copyright; $rss_date = $RSS_DOC->channel->pubDate; //Loop 
through each item in the RSS document foreach($RSS_DOC->channel->item as 
$RSSitem) { $item_id = md5($RSSitem->title); $fetch_date = date("Y-m-j G:i:s"); 
//NOTE: we don't use a DB SQL function so its database independant $item_title 
= $RSSitem->title; $item_date = date("Y-m-j G:i:s", 
strtotime($RSSitem->pubDate)); $item_url = $RSSitem->link; echo "Processing 
item '" , $item_id , "' on " , $fetch_date , "
"; echo $item_title, " - "; echo $item_date, "
"; echo $item_url, "
"; // Does record already exist? Only insert if new item... $item_exists_sql = 
"SELECT item_id FROM rssingest where item_id = '" . $item_id . "'"; 
$item_exists = mysql_query($item_exists_sql, $db); 
if(mysql_num_rows($item_exists)<1) { echo "Inserting new item..
"; $item_insert_sql = "INSERT INTO rssingest(item_id, feed_url, item_title, 
item_date, item_url, fetch_date) VALUES ('" . $item_id . "', '" . $feed_url . 
"', '" . $item_title . "', '" . $item_date . "', '" . $item_url . "', '" . 
$fetch_date . "')"; $insert_item = mysql_query($item_insert_sql, $db); } else { 
echo "Not inserting existing item..
"; } echo "
"; } // End of form // } catch (Exception $e) { echo 'Caught exception: ', 
$e->getMessage(), "\n"; } ?>

Original issue reported on code.google.com by stanley...@gmail.com on 8 Aug 2011 at 9:07

GoogleCodeExporter commented 8 years ago
Hi there,

What you posted here is just the source code. Did you upload the .php file to a 
server that runs php? If you try to open this file when it is located on your 
computer, and you have no server(/php) software running, it won't work. 

By the way, you have now posted your username and password in this source code. 
Please be smart and remove it.

Original comment by niels...@gmail.com on 7 Jun 2012 at 8:45