Forum Moderators: coopster
I'm working on a CPanel on my website that gives me the posibility to edit both the blog, news and shoutbox. So far I'm done with adding new: news, shout & blog. But I'm stuck when it comes to deleting. Like if someone is spamming my shoutbox I want to be able to log in and delete the spam shout.
I wish I had some code to show you for the delete part, but I dont even know where to start..
Anyone have any good solutions for this or some guidelines?
Regards,
Clown
<?php$file = "store/news.txt";
$news = file($file);
foreach ($news as $key => $value) {
$key = $key+1;
echo "<table border=0 cellpadding=0 cellspacing=1 bgcolor=" . $td[0] . "><tr><td bgcolor=" . $td[3] . ">" . $value . "</td><td bgcolor=" . $td[3] . " align=center><a href=delete.php?type=news&id=" . $key . ">Delete</a></td></tr></table>";
}
?>
and I'm now working on the delete.php file.. What I've got so far is:
<?php$file = "store/news.txt";
$selLine = $_GET['id'];
$news = file($file);
?>
So what I wonder now is. On the delete link I have numbers for what line each news are on in the news.txt file. But in the delete.php, how do I pull out that single line and just overwrite it with a empty space?
Do I have to add an foreach and when I come to the selected number I just skip that one, and at the end I write the everything back to the news.txt file?
This is the code I used:
I fixed it with the following code:
---
<?php
$selLine = $_GET['id'];
$delType = $_GET['type'];
$file = "store/" . $delType . ".txt";
$news = file($file);
$cnt = 0;
foreach ($news as $key => $line) {
if ($key!= $selLine) { $result[] = $line; }
$cnt+1;
}
if ($key!= 0) {
$fh = fopen($file, "w");
foreach ($result as $nyhet) {
fwrite($fh, $nyhet);
}
fclose($fh);
}
elseif ($key == 0) {
$fh = fopen($file, "w");
fwrite($fh, "");
fclose($fh);
}
?>
---