Jump to content

insert external rss data in database ater lots of record stop


ebchost

Recommended Posts

Everything works perfectly when I work without inserting rss data in the database.

 

Wheb I've started entering data into the database, in the database is write about 200 lines in the table, and then show an error (after about 200 inserted record in database)

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 'Bild'.

 

', 'http://www.vesti-online.com/Sport/Fudbal/144014/Tejgo-Zelim-' at line 1

before these errors, you can see a news item to be inserted into the base hiar: http://moravaprom.com/ebchost/rss_reader.php

 

 

hiar is code of : rss_reader.php

 

<?php

header('Content-Type: text/html; charset=utf-8');

echo "<h1>RSS vesti</h1><hr>";

$serverurl = "";
$username = "";
$password = "";

$database = "";
$rss_sajtovi = "";

mysql_connect($serverurl, $username , $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

$konekcija = mysql_connect("localhost", "morava_rss", "brodolom") or die ("Parametri za povezivanje sa bazom nisu dobri, ili baza ne postoji!");

$sajtovi = mysql_query("SELECT * FROM rss_sajtovi") or die(mysql_error());

$vesti = mysql_query("SELECT * FROM rss_vesti") or die(mysql_error());


while($row = mysql_fetch_assoc( $sajtovi ))
	{
		$id_sajta 	          = $row['ID_SAJTA'];
		$naziv 		  = $row['NAZIV'];
		$url_sajta 	  = $row['URL'];
		$rss_izvor 	  = $row['RSS'];
		$rss_kategorija = $row['kategorija'];
		$rss_odobren 	  = $row['odobren'];
		$korisnik_id 	  = $row['korisnik_id'];
		$kontrola 	  = $row['kontrola'];		

		$url_rss 	= $rss_izvor;

		$rss_link 	= simplexml_load_file($url_rss);

		if($rss_link)
			{
				echo '<h1>'.$rss_link->channel->title.'</h1>';

				$channelimg = $rss_link->channel->image->url;
				echo $channelimg;

				echo "<img src='$channelimg' alt='$rss_link->channel->title' width='400'>";
				echo "<hr>";

				$items = $rss_link->channel->item;

				foreach($items as $item)
					{
						$title                    = $item->title;
						$link                     = $item->link;
						$published_on     = $item->pubDate;
						$description         = $item->description;
						$description_trim = trim($description);
						$image_object     = preg_match_all('/\"(.*?)\"/', $description, $matches);
						$image                 = str_replace( '"','',$matches[0][0]);

?>
							<div style='overflow:hidden; width:420px; padding: 10px; border-style:solid; border-width: 1px; margin: 5px; '>
								<?php
									echo '<h2><a href="'.$link.'">'.$title.'</a></h2>';
								?>	
									<div style='overflow:hidden;margin:5px; float: left;'><?php echo "<img src='$image' alt='$rss_link->channel->title' width='200'>";?></div>
									<div><?php echo strip_tags($description_trim);?></div>
								<?php
									echo '<span>('.$published_on.')</span>';
								?>
							</div>
<?php
								$sql= "INSERT INTO `rss_vesti` VALUES('', '$id_sajta', '$title', '$image', '$description', '$link', '$published_on')";
                           						mysql_query($sql,$konekcija)or die(mysql_error());
					}
			}
}
?>

There is probably a sql special character as part of the data. You should echo the $sql variable as part of the die(...) statement so what we could see exactly what the query is, right before the Bild point where the syntax failed.

 

Ultimately, you will probably find that the error is because you must escape ALL string data values being put into a query statement so that any special sql characters in the data don't break the sql syntax. See this link - mysql_real_escape_string

There is probably a sql special character as part of the data. You should echo the $sql variable as part of the die(...) statement so what we could see exactly what the query is, right before the Bild point where the syntax failed.

 

Ultimately, you will probably find that the error is because you must escape ALL string data values being put into a query statement so that any special sql characters in the data don't break the sql syntax. See this link - mysql_real_escape_string

 

i think that is ok now

 

i will add lot`s of rss source, and then i will see :)

 

thankse :)

 

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.