...

View Full Version : Guestbook problem



stophon4
04-13-2004, 10:58 PM
I made a php guestbook, but it isn't working? is there anything wrong with this code?



<?php
$blacklist = 'blacklist.dat';$IP = getenv (REMOTE_ADDR);if (!file_exists ($blacklist)) { die("Error: $blacklist does not exist.");}$h = fopen ($blacklist, 'r');while (!feof ($h)) { $line = fgets ($h, 4096); $line = trim ($line); if ($line == $IP){ header("location: ban.php"); }}fclose($h);
if(isset($_POST['submitted']));
{
if(($_POST['Name']=="")&&($_POST['comments']=="")){
echo ("");
}else{
$IP = getenv (REMOTE_ADDR);
$file = fopen("guestbook.php", "a");
fputs($file, '<table class="post"><tr><td>');
fputs($file, '<hr>');
fputs($file, $_POST['Name']);
fputs($file, '<HR>');
fputs($file, '<center>');
fputs($file, $_POST['comments']);
fputs($file, '<br>');
fputs($file, '<font color="CDCDCD" size=2>');
fputs($file, $IP);
fputs($file, '</font><hr><hr>');
fputs($file, '</td></tr></table>');
fclose($file);
header("Location:gb.php");
}
}
$IP = getenv (REMOTE_ADDR);
if($IP=='64.123.8.82')
{
$Name = "Fanstop.tk";
}
else if($IP=='12.202.20.222')
{
$Name = "Stophon4";
echo ("<form action='bg.php' method='post'><b>Ban an IP:</b> <INPUT type=text Name='ban'><INPUT type='Submit' value='Ban The IP!!' Name='banned'></form><br>");
if(isset($_POST['banned']));
{
$blacklist = fopen("blacklist.dat", "a");
fputs($blacklist, $_POST['ban']);
fclose($blacklist);
}
}
else if($IP=='211.29.136.12')
{
$Name = "RamboBones";
}
else
{
$Name = "Guest";
}
echo ("Hello $Name,");
?>
<html>
<head>
<title>Guestbook</title>
<style>
.post{
width:500;
background-color:"CDCDCD";
}
</style>
</head>
<body bgcolor=gold>
<font size=7><center><b><u>Guest Book</u></b></font><br><br>
<?php
include("guestbook.php");
?>
<SCRIPT language="JavaScript">
function Smile()
{
document.post.comments.value += "<img src = smile.gif >";
}
function Smiley()
{
document.post.comments.value += "<img src = mrsmile.gif >";

}
function mad()
{
document.post.comments.value += "<img src = mad.gif >";
}
function shock()
{
document.post.comments.value += "<img src = shock.gif>";
}
function cool()
{
document.post.comments.value += "<img src = cool.gif>";
}
</SCRIPT>
<form Name="post" action="gb.php" method="post">Sign The Guestbook &nbsp;&nbsp; <IMG src = "smile.gif" onclick="Smile()"> <IMG src = "mrsmile.gif" onclick="Smiley()"> <IMG src = "mad.gif" onclick="mad()"> <img src = "shock.gif" onclick="shock()"> <img src = "cool.gif" onclick="cool()">
<Br><hr>Your Name: <input type=text MAXLENGTH=10 Name="Name"><br>Comments: <textarea rows=10 cols=100 Name="comments"></textarea><br><input type="submit" Value="Leave your comments" name="submitted"></form>
</body>
</html>

All help is greatly appreciated :thumbsup:

Nightfire
04-14-2004, 12:28 AM
What's not working on it? Getting any errors?

stophon4
04-14-2004, 08:48 PM
Yes, I get a parse error on the </html> line :confused:

Nightfire
04-14-2004, 08:52 PM
Not sure why, but you have a semi-colon on this line, which shouldn't be there


if(isset($_POST['submitted']));

raf
04-14-2004, 09:13 PM
Yes, I get a parse error on the </html> line :confused:If you get a parse error on the last line, then this usualy means you missed a closing curly bracket.

If you'd indent your code better --> specially the first line, and use an editor that shows the bracket-pairs, then you'll instantly find where you went wrong.

stophon4
04-14-2004, 09:32 PM
that's fixed :thumbsup: But it still doesn't write to the blacklsit.dat file, and when it is done it doesn't go, I would fix it with header(location: bg.php) but it doesn't work since I am aready using that.

BTW how do you write to the top of the page, not the bottem, do I use some other then "a" in the w/r/a in the file open spot?

raf
04-14-2004, 09:42 PM
check the sticky with the FAQ's

stophon4
04-15-2004, 12:28 AM
I did, I just don't understand it... What do I have to add?
sorry for not understanding, I am VERY new to php...

stophon4
04-16-2004, 12:26 AM
How can I do a break in the source with the writing to the document? I don't mean <br> written into the source, just a new line, I can't have it on the same line. Is this possible?

zigo86
04-16-2004, 12:55 AM
newline: \n

Mate! Sort your first line out!

zigo

stophon4
04-16-2004, 01:02 PM
Yeah, sorry.... I just couldn't find that anywhere.... I'll go to more php websites before I come to this forum. Sorry about that :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum