Home arrow HTML arrow Page 4 - 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 / 23
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

TOOLS YOU CAN USE

advertisement
Using htmlArea and a Database to Maintain Content on a Website - How to Display the Saved Contents
(Page 4 of 4 )

The contents will have been saved with the appropriate HTML code and, when retrieved, will need to be integrated into an HTML page. Assuming a hyperlink such as the following:


<a href="gettext.php?itemnumber=7">About Hermione</a>,

the contents might be retrieved and displayed using the following “gettext.php” file :



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Article</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="author" content="" />
<link rel="stylesheet" type="text/css" href="style/template.css" title="template" />
<!--local style elements here-->
<style type="text/css">
</style>
</head>
<body>
<!—insert the item here-->
<?php
//database information and database functions
include 'connection.php';
include 'dbfunctions.inc';
/**************************************************/
$itemnumber=@$HTTP_GET_VARS["itemnumber"];
$strsql = "Select title, description, topic, username, contents, ".
"Date_Format(whenadded,'%M %e,%Y') AS formatted ".
"From item WHERE id = $itemnumber";
$connection = @ mysql_connect($hostname, $username,$password)
or die("Cannot connect to database");
if (! mysql_selectdb($databasename, $connection))
 showerror();
if (!($result = @ mysql_query($strsql, $connection))) 
 showerror();
$row=mysql_fetch_array($result);
echo "<h3>$row[title]</h3>";
echo "$row[topic]<br />";
echo "$row[contents]";
? >
</body>
</html>

You’ll probably want to lay out your page in a more attractive fashion but the above code shows you how any formatting added by the user has been saved to the database and retrieved exactly as the user entered.

Conclusion

We have seen how the combination of htmlArea and a database can greatly simplify adding content to a website. This control converts a textarea into a “word processor” giving the user the freedom to format text as (s)he sees fit and it frees the webmaster from having to mark up text. You can cut out the middle man and have content added directly to your site.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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