Forum Moderators: coopster
Name(with mailto link) - date
----------------------------------------------------------------------
Message: (and then the message)
New message
.. can anybody help me out?
<title></title>
<?
$filename = 'install.php';
if (file_exists($filename)) {
echo("<META HTTP-EQUIV=Refresh CONTENT='1; URL=install.php'>");
}
if(isset($_POST['Submit']))
{
?><table width="100%" border="0" cellspacing="1" bordercolor="#000000" bgcolor="#333333">
<tr>
<td width="432"><?
$dataf = "posts.txt";
$name = $_POST['name'];
$message = $_POST['message'];
$mail = $_POST['mail'];
if (!$name)
{ $name = "Anonymous"; }
else $name .= " Skrev:";
//word censors
$message = str_replace("#*$!","****",$message);
$message = str_replace("bitch","****",$message);
$message = str_replace("#*$!","****",$message);
$message = str_replace("#*$!","****",$message);
$message = str_replace("bull#*$!","****",$message);
$message = str_replace("#*$!","****",$message);
$message = stripslashes($message);
$comfile = file($dataf);
if ($message!= "") {$file = fopen("$dataf","a");
$write = fwrite($file,"<table width='90%' border='0' align='center' cellspacing='1' bgcolor='#333333'>
<tr>
<td bgcolor='#000000'><a href=\"mailto:$mail\">$name</a></td>
</tr>
<tr>
<td bgcolor='#000000'>$message</td>
</tr>
</table><br><br>");
fclose($file);
}
else
{
echo"Du må fylle ut meldingsfeltet! ";
}
if($write == TRUE)
{
echo "Meldingen har blitt lag til!";
}
else
{
echo"Feil i meldingen";
}
?></td>
</tr>
</table><? }?>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#333333">
<tr>
<td width="432"><form name="guestbook" action="" method="post">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Navn</td>
<td><input name="name" type="text" id="name" /></td>
</tr>
<tr>
<td>Mail</td>
<td><label>
<input name="mail" type="text" id="mail" />
</label></td>
</tr>
<tr>
<td>Melding</td>
<td><textarea name="message" id="message"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Legg til" />
<input type="reset" name="Reset" value="Fjern" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form></td>
</tr>
</table>
<br>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td class="style3"><em><strong>Meldinger</strong></em>::</td>
</tr>
<tr>
<td><? include("posts.txt");?></td>
</tr>
</table>
can anybody help out? :)
this is part that needs to be changed
if ($message!= "") {$file = fopen("$dataf","a");
$write = fwrite($file,"<table width='90%' border='0' align='center' cellspacing='1' bgcolor='#333333'>
<tr>
<td bgcolor='#000000'><a href=\"mailto:$mail\">$name</a></td>
</tr>
<tr>
<td bgcolor='#000000'>$message</td>
</tr>
</table><br><br>");
fclose($file);
you need to read the data from the file into a variable
I would then close the file, then reopen with a 'w' flag
then write your new comment to the file
then write the old data back to the file
then close the file again
that will invert the comments
if ($message!= "") {
$myolddata = file_get_contents [php.net]($dataf);
$file = fopen("$dataf","w");
fwrite($file,"<table width='90%' border='0' align='center' cellspacing='1' bgcolor='#333333'>
<tr>
<td bgcolor='#000000'><a href=\"mailto:$mail\">$name</a></td>
</tr>
<tr>
<td bgcolor='#000000'>$message</td>
</tr>
</table><br><br>");
fwrite($file,$myolddata);
fclose($file);
- I grabbed the content with file_get_contents
- then opened the file with 'w' instead of 'a', this opens the file for writing only, truncates the file to zero length and puts the pointer at the beginning of the file
- I then left the original write
- then added a second write to put the old info back in the file
it worked fine :)) only one bug with it.. when you now post a coment, the "error" comes up that it's an error in the message, but the message is still posted and works, so i just changed the error message to that the message was added.. :)
so thanx alot for helping me and for explaining what you did so I could learn from it :D
Otherwise, nice going guys and thanks for listening!
Del
to make that message work just change this line
fwrite($file,"<table width='90%' border='0' align='center' cellspacing='1' bgcolor='#333333'>
back to
$write = fwrite($file,"<table width='90%' border='0' align='center' cellspacing='1' bgcolor='#333333'>
my fault
I also agree with Del but I didn't want to get too far into that at the moment. Once that text file gets ridiculously huge you will want to find a way to reduce it. Then we can go into comma/tab/char delimited files or flat file databases. ;)