Home arrow HTML arrow Page 3 - Using htmlArea and a Database to Maintain Content on a Website
HTML

Using htmlArea and a Database to Maintain Content on a Website


If you wish to develop a website that others can contribute to, one option is to have text files sent as e-mail attachments, convert these to HTML and then upload the file. There is, however, a better way! If the people making submissions to your site are capable of using a word processor then things can be done much more efficiently. This article will show you how to use a free component called htmlArea and a database to handle the addition and display of content on your website. Some knowledge of HTML, databases and server-side scripts is assumed.

Author Info:
By: Peter Lavin
Rating: 5 stars5 stars5 stars5 stars5 stars / 29
May 03, 2004
TABLE OF CONTENTS:
  1. · Using htmlArea and a Database to Maintain Content on a Website
  2. · Download and Install
  3. · Saving Content
  4. · How to Display the Saved Contents

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials