Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Guestbook problem

    I made a php guestbook, but it isn't working? is there anything wrong with this code?

    PHP 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 ($h4096); $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

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    What's not working on it? Getting any errors?

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, I get a parse error on the </html> line

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Not sure why, but you have a semi-colon on this line, which shouldn't be there
    PHP Code:
    if(isset($_POST['submitted'])); 

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by stophon4
    Yes, I get a parse error on the </html> line
    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.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #6
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that's fixed 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?

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    check the sticky with the FAQ's
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #8
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did, I just don't understand it... What do I have to add?
    sorry for not understanding, I am VERY new to php...

  • #9
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #10
    New Coder
    Join Date
    Apr 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    newline: \n

    Mate! Sort your first line out!

    zigo

  • #11
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •