View Poll Results: What do you think?

Voters
11. This poll is closed
  • It's cool

    8 72.73%
  • It's crap

    3 27.27%

[PHP][SOURCE] Guestbook

Results 1 to 4 of 4
  1. #1
    Banned Monsta. is offline
    BannedRank
    Jun 2008 Join Date
    England - MerseLocation
    1,221Posts

    [PHP][SOURCE] Guestbook

    This is just a really quick half-hour project I started due to bordem.

    Anyway, it's all one page and the SQL file will be posted too.

    guestbook.php
    PHP Code:
    <?php
    echo '<html>
    <head>
    <title>My Guestbook</title>
    </head>'
    ;
    //mysql
    $db "guestbook"//your DB name
    $pass "hello123"//your DB password
    $user "root"//your DB username
    $host "localhost"//where is your DB hosted? [usually localhost]
    $connect = @mysql_connect($host$user$pass) or die ('Sorry, I can not connect to your MySQL Database!');
    mysql_select_db($db) or die ('Sorry, I can not open your MySQL Database!');
    //mysql

    //config
    $admin_ip "127g.0.0.1"//PUT YOUR REAL IP HERE!
    //config

    //functions
    function protect($str){
        
    $new strip_tags($str);
        return 
    $new;
    }
    function 
    file_extension($filename){
    return 
    end(explode("."$filename));
    }
    //functions

    if($_POST[send_message]){
        
    $name protect($_POST['name']);
        
    $web protect($_POST['web']);
        
    $avatar protect($_POST['avatar']);
        
    $email protect($_POST['email']);
        
    $comment protect($_POST['comment']);
        
    $ip $_SERVER['REMOTE_ADDR'];
        
    $date date("F jS Y");
        if(!
    $name || !$web || !$email || !$comment || !$ip || !$date){
            echo 
    'All fields are required!<br /><a href="guestbook.php">Back</a>';
        }else{
            if(!
    $avatar){
                
    $avatar 'http://i28.tinypic.com/29zyayv.jpg';
            }else{
                
    $formats = array('jpeg''jpg''tiff''png''gif''bmp');
                if(!
    in_array(file_extension($avatar), $formats)){
                    
    $avatar 'http://i28.tinypic.com/29zyayv.jpg';
                }else{
                    
    $avatar $avatar;
                }
            }
            
    $f str_replace('http://'''$web);
            
    $f str_replace('www.'''$f);
            
    $web 'http://www.' $f '/';
            if(
    strpos($email".") == false || strpos($email"@") == false){
                echo 
    'You must enter a valid E-Mail!<br /><a href="guestbook.php">Back</a>';
            }else{
                
    mysql_query("INSERT INTO `messages` (`name`, `web`, `email`, `avatar`, `comment`, `ip`, `date`) VALUES ('$name', '$web', '$email', '$avatar', '$comment', '$ip', '$date');");
                echo 
    'Thank you for your comment, <b>'.$name.'</b>!<br /><a href="guestbook.php">Return to the Guestbook!</a>';
            }
        }
    }else{
        echo 
    'Welcome to my guestbook!<br /><hr />';
        
    $msgs mysql_query("SELECT * FROM messages ORDER BY `id` DESC");
        if(
    mysql_num_rows($msgs) == 0){
            echo 
    'Sorry, there are no messages!<br />Why not leave one below?';
        }else{
            while(
    $r mysql_fetch_array($msgs)){
                
    $name $r["name"];
                
    $web $r["web"];
                
    $email $r["email"];
                
    $avatar $r["avatar"];
                if(
    $_SERVER['REMOTE_ADDR'] == $admin_ip){
                    
    $ip $r["ip"] . ' - ';
                }else{
                    
    $ip '';
                }
                
    $comment $r["comment"];
                
    $date $r["date"];
                echo 
    '<table width="284" border="0" cellpadding="0" cellspacing="0">
        <tbody>
            <tr>
                <td style="font-size: 7px; vertical-align: bottom;"><img src="http://i26.tinypic.com/30siwk8.png" width="8" border="0" height="8"></td>
                <td style="font-size: 7px; vertical-align: bottom; background-color: rgb(221, 221, 221);"><img src="http://i26.tinypic.com/hrhohx.jpg" width="268" border="0" height="1"></td>
                <td style="font-size: 7px; vertical-align: bottom;"><img src="http://i25.tinypic.com/3127mz7.png"></td>
            </tr>
        </tbody>
    </table>

    <table style="margin-top: -2px;" width="284" border="0" cellpadding="0" cellspacing="0">
        <tbody>
            <tr>
                <td colspan="3" style="background-color: rgb(221, 221, 221);" align="center">
                    <div style="padding: 0pt 8px;">
                        <table width="100%" cellpadding="0" cellspacing="0">
                            <tbody>
                                <tr>
                                    <td width="50" valign="top"><a href="'
    .$web.'" target="_blank"><img size="q" height="50" width="50" style="border: 1px solid rgb(153, 153, 153);" src="'.$avatar.'" alt="'.$name.'" title="'.$name.'"></a></td>
                                    <td width="8"></td>
                                    <td valign="top">'
    .$comment.'<br />'.$ip.''.$date.'</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>

    <table width="284" border="0" cellpadding="0" cellspacing="0">
        <tbody>
            <tr>
                <td style="font-size: 8px;" valign="top"><img src="http://i32.tinypic.com/21wp4y.png" width="24" border="0"></td>
                <td style="font-size: 8px;" valign="top"><img src="http://i30.tinypic.com/wjgks0.png" width="236" border="0" height="9"></td>
                <td style="font-size: 8px;" align="right" valign="top"><img src="http://i26.tinypic.com/2qbc9yd.png" border="0" height="9"></td>
            </tr>
        </tbody>
    </table><br />'
    ;
            }
        }
        echo 
    '<hr /><form method="post">
        <table>
            <tr>
                <td>Name:</td>
                <td><input type="text" name="name" size="25"></td>
            </tr>
            <tr>
                <td>Website:</td>
                <td><input type="text" name="web" size="25"></td>
            </tr>
            <tr>
                <td>E-Mail:</td>
                <td><input type="text" name="email" size="25"></td>
            </tr>
            <tr>
                <td>Avatar:</td>
                <td><input type="text" name="avatar" size="25"></td>
            </tr>
            <tr>
                <td>Message:</td>
                <td><textarea cols="30" rows="5" name="comment"></textarea></td>
            </tr>
        </table>
        <input type="submit" name="send_message" value="Send Message"></form>'
    ;
    }
    echo 
    '</html>';
    ?>
    mysql.sql
    PHP Code:
    CREATE TABLE IF NOT EXISTS `messages` (
      `
    idint(90NOT NULL AUTO_INCREMENT,
      `
    namevarchar(30NOT NULL,
      `
    webvarchar(150NOT NULL,
      `
    emailvarchar(150NOT NULL,
      `
    commentvarchar(200NOT NULL,
      `
    ipvarchar(90NOT NULL,
      `
    datevarchar(90NOT NULL,
      `
    avatarvarchar(200NOT NULL,
      
    PRIMARY KEY (`id`)
    ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=
    Images:



    The least you could do is add credits :)

    - m0nsta.


  2. #2
    :) Horizon is offline
    MemberRank
    Jan 2009 Join Date
    Illinois, U.S.Location
    2,381Posts

    Re: [PHP][SOURCE] Guestbook

    Not bad for a half an hour job.

  3. #3
    Venture Adventure Tyler is offline
    LegendRank
    Nov 2008 Join Date
    United KingdomLocation
    4,441Posts

    Re: [PHP][SOURCE] Guestbook

    I should do more stuff like this.
    :P

  4. #4
    The Gamma..? EliteGM is offline
    MemberRank
    Jul 2006 Join Date
    NandolandLocation
    4,077Posts

    Re: [PHP][SOURCE] Guestbook

    For a half an hour not bad indeed ;]
    Make a .css with it :D Do something about the looks.



Advertisement