my first guestbook

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
filyr
Forum Newbie
Posts: 5
Joined: Wed Sep 23, 2009 7:04 pm

my first guestbook

Post by filyr »

some questions about my so called guestbook :P

Code: Select all

if (isset($_POST['input'])) {
    
        $msg = $_POST['text'];
        $username = $_POST['name'];
        $timedate = date("F j, g:i a");
        $saving = $_REQUEST['saving'];
        
        function smiley($msg)
        { 
          $msg = ereg_replace(":D","<img src='smileys/cheesy.gif'>", $msg); 
          $msg = ereg_replace(":\(","<img src='smileys/angry.gif'>", $msg);
          $msg = ereg_replace(":)","<img src='smileys/wink.gif'>", $msg); 
          return $msg; 
        } 
        
        if($msg=="" or $username=="")
        {
        print "<script>alert('Please enter your username and message');</script>";
        print "<script>window.history.go(-1);</script>";
        
        }
        
        else if(strlen($msg)>1024)
        {
        print "<script>alert('Message too long');</script>";
        print "<script>window.history.go(-1);</script>";
        
        }
        
        else 
        {
 
        $post = "<tr><td><b>" . trim($username) . "</b> skrev: <br> <br>" . trim(smiley($msg)) . "<br><br><font size='2' color='grey'>" . $timedate . "</tr></td>";
        
        $file = "data.txt"; 
     
        $fp = fopen($file, "a") or die("Couldn't open $file for writing!"); 
        fwrite($fp, $post) or die("Couldn't write values to file!"); 
     
        fclose($fp); 
        echo "Saved to $file successfully!";
        
        
    
        
        }
And heres the form:

Code: Select all

<form action="input.php?saving=1" method="POST" name="form1">
    
    <tr><td>Namn:</td></tr>
    <tr><td><input type="text" name="name" class="texta"/></tr></td>
    <tr><td>Inlägg:</tr></td>
    <tr><td><textarea rows="10" cols="40" name="text"></textarea></tr></td>
    <tr><td><input type="submit" value="Posta" name="input"></tr></td>
    </form>


1. how to i make the text file save the posts instead of re-writing it every time?

2. my if-cases doesnt seem to work ( if the message is longer than 1024 chars, if username or msg =="" etc.. ) can you help me here please? :)
uyewq
Forum Newbie
Posts: 22
Joined: Thu Sep 17, 2009 6:21 am

Re: my first guestbook

Post by uyewq »

filyr wrote: 2. my if-cases doesnt seem to work ( if the message is longer than 1024 chars,
because line below says that if if the message is longer than 1024 chars do not work and give alert

Code: Select all

else if(strlen($msg)>1024)
You can increase 1024 as you wish

Code: Select all

else if(strlen($msg)>16384)
bye
Post Reply