Using htmlArea and a Database to Maintain Content on a Website - Download and Install
(Page 2 of 4 )
Excellent installation instructions are provided by interactivetools at their site so follow them and install htmlArea. However, there is one change you will probably want to make. If you follow the instructions given in the link above, you will need to place any page that uses htmlArea in the “htmlarea” directory. It is much more likely that you will want to access this control from a page in your server’s root directory. To do so, change the line of code that reads, _editor_url = ""; to _editor_url = "htmlarea/"; .
You can embed an htmlArea control that will work from your root directory using the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>htmlArea</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="your name" />
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "htmlarea/"; // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera') >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
document.write(' language="Javascript1.2"></scr' + 'ipt>');
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// -->
</script>
</head>
<body>
<script language="JavaScript1.2" defer>
editor_generate('contents');
</script>
<p align="center">
<textarea name="contents" cols="40" rows="12" readonly>
</textarea>
</p>
</body>
</html>
Save this code, upload it to your server’s root directory and try it out. If you’ve done everything correctly you should see an htmlArea in place of the textarea named “contents”. Try out the various features and see what it is capable of.
Database Table
Let’s define the database table that will store the contents of an htmlArea. We’ll name the table “items” and give it the following structure:
| Field Name | Data Type | Properties |
| id | int(11) | PRIMARY KEY |
| title | varchar(35) | Not Null |
| topic | varchar(35) | Not Null |
| author | varchar(15) | Not Null |
| contents | text | Not Null |
| whenadded | timestamp | |
| reviewed | tinyint (4) | |
A few more fields than you imagined perhaps, but they all do serve a purpose. The “id” field will be a unique identifier and should probably be “auto_increment” type. “title” and “author” are self explanatory and “contents” will hold what’s typed into the htmlArea. The ‘whenadded’ field is a ‘timestamp’ data type so it will record the date and time that a record is added. Depending upon your needs, the ‘reviewed’ field may or may not be necessary but it will allow you to vet (preview) content before it is posted to your site. For instance, a where clause in your SQL such as, “WHERE reviewed =1”, would keep items not yet reviewed from showing up on your site.
Next: Saving Content >>
More HTML Articles
More By Peter Lavin