HTML
  Home arrow HTML arrow Page 3 - Using htmlArea and a Database to Maintain ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
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? 
HTML

Using htmlArea and a Database to Maintain Content on a Website
By: Peter Lavin
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2004-05-03

    Table of Contents:
  • Using htmlArea and a Database to Maintain Content on a Website
  • Download and Install
  • Saving Content
  • How to Display the Saved Contents

  • 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


    Using htmlArea and a Database to Maintain Content on a Website - Saving Content


    (Page 3 of 4 )

    I don’t intend to discuss here how a form is submitted from a web page. If you’ve read this far, you probably know how to do this anyway. If not there are plenty of online tutorials available on this subject. Let’s assume that our htmlArea control is part of a “form” and the “action” attribute has been set to a file in the current directory called “processform.php”. For the sake of clarity, the topics used in the select control below have been hardcoded. In real-life these would most likely be created dynamically (or perhaps in this case magically) from a database. The HTML code for the form in your web page might look like the following:


    <form name="frmitem" method="post" action=" processform.php">
    <table border="0" >
    <td>Title: </td><td><input type="text" name="title" maxlength=35></td>
    </tr>
    <td>Topic:</td>
    <td><select name="topic">
    <option>Ghosts</option>
    <option>Goblins</option>
    <option>Harry Potter</option>
    <option>Haunted Places</option>
    <option>Hermione</option>
    <option>Ron</option>
    </select></td>
    </tr>
    <tr>
    <td colspan=2 valign ="top">Contents: </td></tr><tr>
    <td colspan=><textarea name="contents" rows="22" cols="40"></textarea></td>
    </tr>
    <tr>
    <td align "center" colspan="2">
    <input type="submit" value="Send" >   <input type="reset" value="Clear"></td>
    </tr>
    </table>
    </form>

    The “textarea” named “contents” will become an htmlArea control but will not appear differently in the source code. When this form is submitted it does not need to be handled in any special way. Any formatting done by the user will be captured as HTML code in your database.

    Just as your form does not require any special coding, nor does your server-side script.


    <?php
    /* include files holding connection information and additional
    functions */

    include 
    'connection.php';
    include 
    'dbfunctions.inc';
    /***************************************************/
    $user 
    "guest";
    //retrieve information posted from form
    $title=@$HTTP_POST_VARS["title"];
    $description=@$HTTP_POST_VARS["description"];
    $topic=@$HTTP_POST_VARS["topic"];
    $contents=@$HTTP_POST_VARS["contents"];
    //programmer created function from the dbfunctions.inc include file
    opendatabase();
    $strsql = "INSERT INTO items ".
      "VALUES(null,'$title', $topic', ".
    "'$user','$contents',null, 0)"; 
    $connection = @ mysql_connect($hostname, $username,$password)
      or die("Cannot connect to database");
    if (! mysql_selectdb($databasename, $connection))
      showerror();
    if (!($result = @ mysql_query($strsql, $connection))) 
      header("Location: mainpage.php?status=F");
    else
     header("Location: mainpage.php?status=T");
    ? >

    Again, for the sake of simplicity, we have used a literal for the value of the variable “$user” and have not verified any of the data submitted. Also, functions to open the database are not shown but are assumed to be in the “dbfunctions.inc” file.

    More HTML Articles
    More By Peter Lavin


     

    HTML ARTICLES

    - Using a 3D HTML Table as a Recordset
    - Building a 3D HTML Table
    - Maximizing and Restoring HTML Images: Layer ...
    - Completing Construction of a Database Form w...
    - Maximizing and Restoring Images in a Tabular...
    - Building the Recordset for an HTML Database ...
    - Laying Out a Database Form with HTML
    - Tabular Database Form Functions with HTML
    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT