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