Administration
  Home arrow Administration arrow Page 5 - Talk To Me!
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ADMINISTRATION

Talk To Me!
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 1
    2001-03-12

    Table of Contents:
  • Talk To Me!
  • The Job
  • Building The Foundation
  • Mole In A Hole
  • Speak Now, Or Forever Hold Your Peace
  • Of Trees And Branches
  • Closing The Loop
  • The Last Word

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Talk To Me! - Speak Now, Or Forever Hold Your Peace
    (Page 5 of 8 )

    Next, I'm going to construct a form which will ask for some basic user information, and allow the user to enter a comment on the article. Once that form is submitted, a PHP script will process the information entered into it and store the result in the database via an INSERT operation.

    For purposes of convenience, both the initial form and the result page have been embedded in the same PHP script, "post.php", with the $submit variable used to decide which page is displayed. Here's the initial form.


    <?php // post.php if($submit) { // form has been submitted // form processing code } else { // display initial form ?> <form action="<? echo $PHP_SELF; ?>" method="post"> <input type="hidden" name="replytopost" value="<?php echo $replytopost; ?>"> <input type="hidden" name="section" value="<?php echo $section; ?>"> <input type="hidden" name="article" value="<?php echo $article; ?>"> <table border="0" cellspacing="5" cellpadding="0"> <tr> <td colspan=2> <font face="Verdana, Arial" size="2" color="Black"><b>Your comment:</b></font><p> </td> </tr> <tr> <td><font face="Verdana, Arial" size="2" color="Black">Name</font></td> <td><input type="text" name="username" size="25"></td> </tr> <tr> <td><font face="Verdana, Arial" size="2" color="Black">Email address</font></td> <td><input type="text" name="email" size="25"></td> </tr> <tr> <td><font face="Verdana, Arial" size="2" color="Black">Subject</font></td> <td><input type="text" name="subject" size="25"></td> </tr> <tr> <td><font face="Verdana, Arial" size="2" color="Black">Comment</font></td> <td><textarea name="post" rows="5"></textarea></td> </tr> <tr> <td colspan=2 align=center><input type="submit" name="submit" value="Add Comment"></td> </tr> </table> </form>

    Here's what it looks like:



    Once the form is submitted, the same script is called upon to process the data.

    <?php // post.php if($submit) { // form has been submitted // process form data include("config.php"); $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); // indicates new comment, not reply if (!$replytopost) { $replytopost = 0; } // correction for empty subject // all form fields should be checked before executing the query if (!$subject) { $subject = "No subject"; } // correction for empty username if (!$username) { $username = "Anonymous"; } $query = "INSERT INTO $table (section, article, subject, post, username, email, replytopost, timestamp) VALUES ('$section', '$article', '$subject', '$post', '$username', '$email', '$replytopost', NOW())"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query . " . mysql_error()); ?> <font face="Verdana, Arial" size="2" color="Black"> Your comment has been posted. Click to <a href="list.php?section=<? echo $section; ?>&article=<? echo $article; ?>">read more comments</a>. <?php } else { // display initial form } ?>

    This script simply checks the form variables, corrects empty ones, and then INSERTs the data into the database. If this is a "new" comment (as opposed to a "reply"), the $replytopost variable is set to 0.

    In case you're wondering what the include() is all about at the top of the script, the file "config.php" simply stores some basic parameters required to connect to the database. Here it is.

    <? // database parameters // alter this as per your configuration $database="db39492"; $table = "comments"; $user = "root"; $pass = "gsfd3k6"; $hostname = "localhost"; ?>

    Once the data has been stored in the database, a success code is returned, and a link offered to read other comments that may have been posted. Let's take a look at that next.

    This article copyright Melonfire 2001. All rights reserved.

    More Administration Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    ADMINISTRATION ARTICLES

    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization
    - Advanced Concepts on Dealing with Files and ...
    - Dealing with Files and Filesystems
    - More Hacks for the User Environment in BSD
    - Personalizing the User Environment in BSD
    - Customizing the User Environment in BSD

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway