Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Trying to Create RSS Feed

Featured Replies

I'm trying to an RSS feed from scratch for a friend's script. The script allows her to post blog posts and updates. However, the script doesn't come with any type of RSS feed set up. So I'm trying to create one for her. However, I'm getting errors.
I am trying to connect the database for her current script up with this RSS feed. So it'll use the updates to automatically update the RSS feed. Does that make sense?
Anyway, the problem is that I'm getting errors. I don't understand why.
First, you can find the RSS Feed's coding at this location: http://pastebin.com/73HhrNQE
The error is as following,

This page contains the following errors:

error on line 38 at column 28: Extra content at the end of the document
Below is a rendering of the page up to the first error.
Can anyone help?

Look like error in line 15

echo "<?xml version='1.0' encoding='UTF-8'?-->
<rss version="2.0">
String is terminated after
version="
You should escape " in version="2.0"
  • Author

 

Look like error in line 15

echo "<?xml version='1.0' encoding='UTF-8'?-->
<rss version="2.0">
String is terminated after
version="
You should escape " in version="2.0"

 

What do you mean 'escape'? I don't understand...

http://pastebin.com/aTDty30d

 

or:

<?php
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "alove_listadmin"); // set database user
define ("DB_PASS", "xxxxxxx"); // set database password
define ("DB_NAME", "alove_listadmin"); // set database name
   
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");
  
$query = "SELECT title, description, url FROM ".table_rss." WHERE status=1 ORDER BY created_date desc";
$getBlogDisplay = mysql_query($query);
  
header("Content-type: text/xml");
  
echo '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
	<title>A Love Letter</title>
	<link>http://aloveletter.co.uk/</link>
	<description>a fanlisting collective</description>
	<language>en-us</language>';
  
  
while($dataBlogDisplay = mysql_fetch_array($getBlogDisplay)){
            
 $title         = escapeXMLVal( $dataBlogDisplay['uTitle'] );
 $link          = escapeXMLVal( $dataBlogDisplay['uID'] );
 $description   = escapeXMLVal( $dataBlogDisplay['uEntry'] );
 $date          = escapeXMLVal( $dataBlogDisplay['uAdded'] );
  
echo "<item>
	<title>$title</title>
	<pubDate>$date</pubDate>
	<link>$link</link>
	<description>$description</description>
</item>";
}
echo "</channel></rss>"; 

function escapeXMLVal($xval){
	$xval = str_replace('&', '&', $xval);
	$xval = str_replace('"', '"', $xval);
	$xval = str_replace('<', '<', $xval);
	$xval = str_replace('>', '>', $xval);
	$xval = str_replace("'", ''', $xval);
	return $xval;
}

?>

 

 

Well, I changed my coding to the one you gave and now I have more errors,

 

 

This page contains the following errors:
error on line 38 at column 23: Extra content at the end of the document
Below is a rendering of the page up to the first error. http://aloveletter.co.uk/ a fanlisting collective en-us'; while($dataBlogDisplay = mysql_fetch_array($getBlogDisplay)){ $title = escapeXMLVal( $dataBlogDisplay['uTitle'] ); $link = escapeXMLVal( $dataBlogDisplay['uID'] ); $description = escapeXMLVal( $dataBlogDisplay['uEntry'] ); $date = escapeXMLVal( $dataBlogDisplay['uAdded'] ); echo " $date $link $description "; } echo "

I don't have access to your db so I can't test mysql, but you are using wrong field names

 

SELECT title, description, url in query

and

uTitle, uID, uEntry, uAdded in while loop


<?php
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "alove_listadmin"); // set database user
define ("DB_PASS", "xxxxxxx"); // set database password
define ("DB_NAME", "alove_listadmin"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

$query = "SELECT title , description, url, created_date FROM ".table_rss." WHERE status=1 ORDER BY created_date desc";
$getBlogDisplay = mysql_query($query);

header("Content-type: text/xml");

echo '<?xml version="1.0" encoding="UTF-8" ?>'.
'<rss version="2.0">
<channel>
<title>A Love Letter</title>
<link>http://aloveletter.co.uk/</link>
<description>a fanlisting collective</description>
<language>en-us</language>';


while($dataBlogDisplay = mysql_fetch_array($getBlogDisplay)){

$title = escapeXMLVal( $dataBlogDisplay['title'] );
$link = escapeXMLVal( $dataBlogDisplay['url'] );
$description = escapeXMLVal( $dataBlogDisplay['description'] );
$date = escapeXMLVal( $dataBlogDisplay['created_date'] );

echo "<item>
<title>$title</title>
<pubDate>$date</pubDate>
<link>$link</link>
<description>$description</description>
</item>";
}
echo "</channel></rss>";

function escapeXMLVal($xval){
$xval = str_replace('&', '&', $xval);
$xval = str_replace('"', '"', $xval);
$xval = str_replace('<', '<', $xval);
$xval = str_replace('>', '>', $xval);
$xval = str_replace("'", ''', $xval);
return $xval;
}

?>
  • Author

 


 

The problem though with this code is you changed,

 

 $title         = escapeXMLVal( $dataBlogDisplay['uTitle'] );
 $link          = escapeXMLVal( $dataBlogDisplay['uID'] );
 $description   = escapeXMLVal( $dataBlogDisplay['uEntry'] );
 $date          = escapeXMLVal( $dataBlogDisplay['uAdded'] );

If you don't have them as UTitle, uID, uEntry, and uAdded, then it won't follow the database. I can't change the database because that follows another script and everything would stop working then.

 

So, I changed the dataBlogDisplay to those above, but otherwise kept the code you gave me. I now have this error,

 

 

This page contains the following errors:
error on line 15 at column 46: Document is empty
Below is a rendering of the page up to the first error.

Edited by Lovelessly

If your query is correct:

$query = "SELECT title , description, url, created_date FROM ".table_rss." WHERE status=1 ORDER BY created_date desc";

 

then you need to map columns named: title , description, url, created_date to RSS

 

 

Fields uTitle, uID, uEntry, uAdded do not exist.

  • Author

If your query is correct:

$query = "SELECT title , description, url, created_date FROM ".table_rss." WHERE status=1 ORDER BY created_date desc";

 

then you need to map columns named: title , description, url, created_date to RSS

 

 

Fields uTitle, uID, uEntry, uAdded do not exist.

 

 

I don't understand. uTitle, etc is how the updates are set up in the database. So how is the script going to know what to take from the database if these (uTitle, etc) aren't somewhere in the RSS?

  • Author

Can you please post "table_rss" structure here?

 

There is no "table_rss". Like I said, I'm using a database from another script that posts the updates. The script doesn't have RSS, so that's what I'm doing. So there is no "table_rss".

 

Here is the updates SQL file though: http://pastebin.com/RRDZApiJ So you can kind of see what I mean. I can't change ANYTHING in this database or it's set up otherwise the script will stop working. So I have to make the RSS work around the database set up.


<?php
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "alove_listadmin"); // set database user
define ("DB_PASS", "xxxxxxx"); // set database password
define ("DB_NAME", "alove_listadmin"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

$query = "SELECT uTitle , uID, uEntry, uAdded FROM wyngs_updates ORDER BY uAdded desc";
$getBlogDisplay = mysql_query($query);

header("Content-type: text/xml");

echo '<?xml version="1.0" encoding="UTF-8" ?>'.
'<rss version="2.0">
<channel>
<title>A Love Letter</title>
<link>http://aloveletter.co.uk/</link>
<description>a fanlisting collective</description>
<language>en-us</language>';


while($dataBlogDisplay = mysql_fetch_array($getBlogDisplay)){

$title = escapeXMLVal( $dataBlogDisplay['uTitle'] );
$link = escapeXMLVal( $dataBlogDisplay['uID'] );
$description = escapeXMLVal( $dataBlogDisplay['uEntry'] );
$date = escapeXMLVal( $dataBlogDisplay['uAdded'] );

echo "<item>
<title>$title</title>
<pubDate>$date</pubDate>
<link>$link</link>
<description>$description</description>
</item>";
}
echo "</channel></rss>";

function escapeXMLVal($xval){
$xval = str_replace('&', '&', $xval);
$xval = str_replace('"', '"', $xval);
$xval = str_replace('<', '<', $xval);
$xval = str_replace('>', '>', $xval);
$xval = str_replace("'", ''', $xval);
return $xval;
}

?>
  • Author

 


 

 

Same error,

 

 

This page contains the following errors:
error on line 15 at column 46: Document is empty
Below is a rendering of the page up to the first error.
  • Author

 

I'm lost, try to replace line 15 with

 

echo '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'.

 

 

Done! Now this error,

 

 

This page contains the following errors:
error on line 49 at column 3: Extra content at the end of the document
Below is a rendering of the page up to the first error.

 

Sorry, I know it's a pain. I REALLY appreciate your help though!!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.