i have news.php, news.txt and add.php.
news.php echoes
pieces[0] pieces[1] pieces[2] pieces[3]
theres are:
[3] = title
[2] = the news
[1] = who posted
[0] = date
i would like have a page that displays each entry with a checkbox next to each one and when the checkbox is checked, that line from the txt file is deleted.
the script i use to write to the txt file is:
<?
echo "<h2><b><u>Current News</u></b></h2>\n";
$data = file('news.txt');
$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo "<U>" . $pieces[3] . "</U><BR>" . $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b><BR><BR>";
}
echo "<hr>\n";
echo "<h2><b><u>Add News</u></b></h2>\n";
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'password here') {
if(!$HTTP_POST_VARS['title']) {
echo "You must enter a title";
exit;
}
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line .= "|" . $HTTP_POST_VARS['title'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
echo "<b>News added!</b>\n";
} else {
echo "Bad Password";
}
}
?>
<form action="<?=$PHP_SELF?>" method="post" name="newsentry">
Title:<BR>
<input type="text" size="30" name="title"><BR>
Your name:<BR>
<select name="name">
<option>Admin1</option>
<option>Admin2</option>
</select>
<br>
The News:<br>
<textarea name="news" cols="40" rows="5"></textarea><br><br>
News Password:<BR>
<input type="password" size="30" name="password"><br><br>
<input type="submit" name="submit" value="Post News" /><br>
<br> <a href="javascript:history.back()">Back</a><br>
</form>
im not exactly sure where to start so if someone could help, that would be great.