Forum Moderators: coopster
I just made a guestbook to my webpage and now I want a counter that shows how many threads it's in my guestbook. Anyone know how the code would look like? I've tried to grab some codes from other guestbook scripts, but no luck.. My guestbook is a simple guestbook with no MySQL, and the code looks like this:
<?
$filename = 'install.php';
if (file_exists($filename)) {
echo("<META HTTP-EQUIV=Refresh CONTENT='1; URL=install.php'>");
}
if(isset($_POST['Submit']))
{
?>
<link href="stil.css" rel="stylesheet" type="text/css" />
<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'];
$hp = $_POST['hp'];
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);
$date = date("Y-d-m H:i:s");
if ($message!= "") {
$myolddata = file_get_contents($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> - $date - <a href=\"$hp\" target=\"new\"><img src=\"bilder/house.jpg\" border=\"0\"/></a></td>
</tr>
<tr>
<td bgcolor='#000000'>$message</td>
</tr>
</table><br><br>");
fwrite($file,$myolddata);
fclose($file);
}
else
{
echo"Du må fylle ut meldingsfeltet! ";
}
if($write == TRUE)
{
echo "Meldingen har blitt lag til!";
}
else
{
echo"Meldingen har blitt lag til!";
}
?></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" style="background:#000000;border:1px solid; border-color:#333333; color:#AAAAAA; font-family:Lucida Grande, Lucida Sans Unicode, Lucida Sans, Verdana, Arial, sans-serif; font-size:10px;" value="..."/></td>
</tr>
<tr>
<td>Mail</td>
<td> <input name="mail" type="text" id="mail" style="background:#000000;border:1px solid; border-color:#333333; color:#AAAAAA; font-family:Lucida Grande, Lucida Sans Unicode, Lucida Sans, Verdana, Arial, sans-serif; font-size:10px;" value="..."/> </td>
</tr>
<tr>
<td>Hjemmeside</td>
<td><input name="hp" type="text" id="hp" style="background:#000000;border:1px solid; border-color:#333333; color:#AAAAAA; font-family:Lucida Grande, Lucida Sans Unicode, Lucida Sans, Verdana, Arial, sans-serif; font-size:10px;" value="http://"/></td>
</tr>
<tr>
<td>Melding * </td>
<td><textarea name="message" id="message" style="background:#000000;border:1px solid; border-color:#333333; color:#AAAAAA; font-family:Lucida Grande, Lucida Sans Unicode, Lucida Sans, Verdana, Arial, sans-serif; font-size:10px; ">....</textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Legg til" style="background:#000000;border:1px solid; border-color:#333333; color:#AAAAAA; font-family:Lucida Grande, Lucida Sans Unicode, Lucida Sans, Verdana, Arial, sans-serif; font-size:12px; " />
<input type="reset" name="Reset" value="Fjern" style="background:#000000;border:1px solid; border-color:#333333; color:#AAAAAA; font-family:Lucida Grande, Lucida Sans Unicode, Lucida Sans, Verdana, Arial, sans-serif; font-size:12px; " />
* må fylles ut </td>
</tr>
</table>
</form></td>
</tr>
</table>
<br>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td><em><strong>Meldinger</strong></em>::</td>
</tr>
<tr>
<td><? include("posts.txt");?></td>
</tr>
</table>
This will make it much easier to count the number of entries, and depending on how you decide to do this, could be as easy as just counting the number of line (for example). If you would like everything to be much easier, you could use a database, however, as you stated, you don't want to use those. :)
So that's the first thing I'd suggest: change the way you store the information.