<pubDate>Sat, 11 Oct 2004 09:00:00 EST</pubDate>
<pubDate>Mon, 05 Sep 2002 14:00:00 GMT</pubDate>
<pubDate>Wed, 14 Oct 2003 17:00:00 +0200</pubDate>
So we will pre populate the date field with present time in this format, but we will have option of changing it. Here is the sample form.
echo "<hr>";
$tm=time(); // time stamp of the present time
$tm=date("D, d M Y H:i:s",$tm); // generating the format
$tm=$tm. " GMT"; // added GMT but you can add your format
echo "<form method=post action=rsspostck.php>
Title<input type=text name=title size=100><br>
Link<input type=text name=page_link size=100><br>
Description<textarea name=description cols=60 rows=5></textarea><br>
Publication Date<input type=text name=pubdate size=35 value='$tm'>Wed,
21 Apr 2005 08:20:47 GMT<br>
<input type=submit value='Add'></form>
";
We will go with a simple date field for storing the RSS feeds, but we will have option of changing it.
require 'config.php';
$title=$_POST['title'];
$link=$_POST['link'];
$description=$_POST['description'];
$pubdate=$_POST['pubdate'];
echo "<hr>";
$sql=$dbo->prepare("insert into rss(title,link,description,pubdate) values(:title,:link,:description,:pubdate)");
$sql->bindParam(':title',$title,PDO::PARAM_STR, 250);
$sql->bindParam(':link',$link,PDO::PARAM_STR, 250);
$sql->bindParam(':description',$description,PDO::PARAM_STR,250);
$sql->bindParam(':pubdate',$pubdate,PDO::PARAM_STR);
if($sql->execute()){
$rss_id=$dbo->lastInsertId();
echo " Thanks .. Your Rss Id = $rss_id ";
}
else{
echo " Not able to add data please contact Admin ";
print_r($sql->errorInfo());
}
<?Php
require 'config.php';
///////// Getting the data from Mysql table for first list box//////////
$sql="SELECT * from rss order by rss_id desc limit 0,6";
///////////// End of query for first list box////////////
$body="<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>Plus2net Free Tutorials on Web programming</title>
<link>https://www.plus2net.com</link>
<description>The latest Tutorials and free codes on Web programming from www.plus2net.com</description>
<copyright>(c) 2005, Plus2net.com. All rights reserved.</copyright>
";
foreach ($dbo->query($sql) as $nt) {
$body .="
<item>
<title> $nt[title]</title>
<link> $nt[link]</link>
<description> $nt[description]</description>
<pubDate>$nt[pubdate]</pubDate>
</item>";
}
$body .="
</channel>
</rss>";
echo $body;
$path="rss.xml";
$filenum=fopen($path,"w");
fwrite($filenum,$body);
fclose($filenum);
?>
After running of this update_rss.php file, one new rss.xml file will be generated. So you must give write permission to this directory to create this file.
Download the code for this tutorial here
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.