Location: PHPKode > projects > Micro Guestbook > add.php
<?php
    require_once('general.php');
    require_once('db/db_connection.php');
    
    if (isset($_POST['submitBtn'])) {
         $name     = (isset($_POST['name'])) ? htmlentities($_POST['name']) : '' ;
         $comment  = (isset($_POST['comment'])) ? htmlentities($_POST['comment']) : '' ;
         $location = (isset($_POST['location'])) ? htmlentities($_POST['location']) : '' ;
         $website  = (isset($_POST['website'])) ? htmlentities(str_replace('http://','',$_POST['website'])) : '' ;
         $email    = (isset($_POST['email'])) ? htmlentities($_POST['email']) : '' ;
         $actDate  = date("Y-m-d H:i:s");
         
         //Minimum name and comment length.
         if ((strlen($name) > 2) && (strlen($comment) > 5)){
             $sql = "INSERT INTO guestbook (name,text,insertdate,location,web,email) VALUES (";
             $sql .= "'".$name."','".$comment."','".$actDate."','".$location."','".$website."','".$email."')";
             $MyDb->f_ExecuteSql($sql);
         }
         
         header("Location: index.php");
    }
    else {

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Micro Guestbook</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
      <div id="main">
        <div id="formheader">Add comment</div>
        <div id="formbody">
          <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="gbook" id="gbook">
            <table align="center">
              <tr><th>Name:</th><td><input name="name" type="text" size="42" maxlength="15" /></td></tr>
              <tr><th>Comment:</th><td><textarea name="comment" cols=32 rows=6></textarea></td></tr>
              <tr><th>Location:</th><td><select name="location"><?php listLocations(); ?></select></tr>
              <tr><th>Website:</th><td><input name="website" type="text" size="42" /></td></tr>
              <tr><th>Email:</th><td><input name="email" type="text" size="42" /></td></tr>
              
              <tr><td colspan="2" align="center"><br/><input class="text" type="submit" name="submitBtn" value="Add comment" /></td></tr>
            </table>  
          </form>

        </div>
        <div id="source">Micro Guestbook 1.1</div>	
      </div>
</body>     
<?php } ?>   
Return current item: Micro Guestbook