Hi,
I’m trying to get my site to automatically update the rss feed when I add news through my “add news” form. Currently the news gets added to the database fine, but it fails to update the xml file. It doesn’t give me any errors either so I’m finding it difficult to find out what’s wrong. Here’s the code, i hope someone can help!
[CODE]<?php
$date=$_POST[‘date’];
$title=$_POST[‘title’];
$text=$_POST[‘text’];
$author=$_POST[‘author’];
if($date==””||$title==””||$text==””||$author==””){
echo ‘You need to fill in all details’;
exit;
}
if (($_FILES[‘music’][‘type’] == “audio/mpeg”) || ($_FILES[‘music’][‘type’] == “application/force-download”) || ($_FILES[‘music’][‘type’] == “application/octet-stream”)) {
$music=’uploads/’.$_FILES[“music”][“name”];
$tmpname=$_FILES[‘music’][‘tmp_name’];
move_uploaded_file($tmpname,$music);
}
$host=’localhost’;
$user=’u0759062′;
$pass=’password’;
mysql_connect($host,$user,$pass);
mysql_select_db($user);
$query=”insert into newstable values (NULL,'”.$date.”‘,'”.$title.”‘,'”.$text.”‘,'”.$author.”‘,'”.$music.”‘)”;
$result=mysql_query($query);
if(mysql_affected_rows()==1){
echo ‘details were successfully added<br>’;
echo ‘<br><a href=”addnews.php”>Add More News</a>’;
}
else{
echo ‘there was a problem’;
}
$query2=”select date, title, text, author, music from newstable order by date”;
$result2=mysql_query($query2);
$body=”<?xml version=”1.0″ encoding=”UTF-8″?>
<rss version=”2.0″>
<channel>
<title>Nutman</title>
<link>http://hermes.hud.ac.uk/u0759062</link>
<description>Electronic Music Producer</description>
“;
while($row = mysql_fetch_array($result2)) {
$body .=”
<item>
<title> $row[title]</title>
<link> $row[link]</link>
<description> $row[text]</description>
</item>”;
}
$body .=”
</channel>
</rss>”;
$path=”rss/rss.xml”;
$filenum=fopen($path,”w”);
fwrite($filenum,$body);
fclose($filenum);
mysql_close()
?>