Hello,
I am trying to incorporate a delete-news script into the admin news section of my site.
I am not using any MYsql - my server does not support that.
The delete-news script I am using (see below) will display my news items, but, when I click a post's delete link nothing happens...
Here is the delete script:
<?
if($action == "delete") {
$data = file('news.dat');
//this next line will remove the single news item from the array
array_splice($data,$id,1);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.dat','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item deleted!<BR><BR>\n";
echo "<a href=\"$PHP_SELF\">Go Back</a>\n";
exit;
}
echo "<H1><u>Current News</u></H1>\n";
$data = file('news.dat');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>\n";
echo " <a href=\"$PHP_SELF?action=delete&id=$key\">Delete</a>\n";
echo "<BR><BR>\n";
}
?>
Here is an example news.dat file(chmod = 777):
10 Jun 2004%~#This is a title%~#this is the post body.
10 Jun 2004%~#This is a test!%~#Yep, just like the title says!
And here is my add-news script:
<?
require('config.php');
if($_POST['do']=='addnew') {
$title=$_POST['title'];
$news=$_POST['news'];
$fp=fopen(NEWS_FILE,"a");
$formatted=str_replace("\r\n","<br>",$news);
$formatted=str_replace("\n","<br>",$formatted);
$newsto=date("d M Y")."%~#".$title."%~#".$formatted;
if(ENCODING=='yes') $newsto=base64_encode($newsto);
fwrite($fp,StripSlashes($newsto)."\n");
fclose($fp);
echo ' news added... ';
}
?>
Can anyone help me with this? How can I get it to delete my entries? Does anyone know of a better delete script? Any help would be greatly appreciated. 🙂
Cheers
micky