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.
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.
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.