Hi,
I have a news section on my site that I want to be able to update using an HTML form. I got the PHP script working except for one problem: the new entry writes over old text. My PHP code is:
<?
$filename = "test.txt";
$theText = $_POST["date"] . ": " . $_POST["news"] . "\r\n";
//$theText = stripslashes($theText); (I don't know what this function does for me, but it doesn't seem to have any effect if I comment it out. Can someone tell me what it does?)
$data = fopen($filename, "r+");
fwrite($data,$theText);
fclose($data);
echo "File Updated";
?>
Just in case, the HTML for my form is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-size: 36px;
color: #FFFFFF;
}
.style2 {
color: #FFFF00;
font-weight: bold;
}
.style4 {color: #FFFF00; font-weight: bold; font-size: 18px; }
-->
</style></head>
<body bgcolor="#0099CC">
<div align="center">
<p><strong><span class="style1">Update News</span></strong></p>
<form name="form1" method="post" action="updatenews.php">
<table width="640" border="0" cellspacing="10" cellpadding="0">
<tr>
<td width="296"><div align="right"><span class="style4">Date</span></div></td>
<td width="314"><input name="date" type="text" id="date" value="MM/DD/YY"></td>
</tr>
<tr>
<td valign="top"><div align="right">
<p class="style4"><br>
News Event </p>
</div></td>
<td><span class="style2">
<textarea name="news" cols="40" rows="10" id="news">Type news event here</textarea>
</span></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
<td> </td>
</tr>
</table>
<p> </p>
<p> </p>
<p class="style2"> </p>
</form>
<p><strong></strong></p>
</div>
</body>
</html>
If you want to understand better what the problem is, go to [deleted for security reasons] and fill out the form. Then go to http://www.wolfband.org/test.txt to see the changes. Thanks for any help.