|
Posted by Dano on 09/27/06 12:22
1. You'll need some sort of database to keep the page content in. I
recommend MySQL, as it's usually on most Web hosting servers. If not,
check with your client's hosting, to see if they can install it. I
think it can even be installed on MS servers.
The database is extremely simple, consisting of one table, with two
fields:
message_id - should be an integer data type, and make the value "1"
message - should be text data type, to hold large quantities of data.
This data type usually holds 65,000 or so characters, or approximately
11 typed pages.
2. You need to connect to the database every time the page is displayed
to a Web site visitor, as well as every time the manager wants to go in
and modify the page content. I use a single .PHP file called
"connect.php. Here's what it contains (ignore the pre tags):
<pre>
<?
$db = mysql_connect("servername", "username", "password");
if (!$db)
{
echo "error!";
}
mysql_select_db("database_name");
?>
</pre>
Substitute your own values for servername, username, password, and
database_name.
3. Now, you'll need to code the display page, so it "fetches" the
contents of the message field in the database. Here's the code (again,
ignore pre tags):
<pre>
<?
include("connect.php"); //pulls in the small .php file from before
$query = "SELECT * from table_name where message_id = '1'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo "<p>".$row["message"]."</p>";
?>
</pre>
That will display the contents of the message field from the database
on the page. It would be helpful if the manager knew a little HTML, as
it can be included in the message field. That way, the message can be
formatted to fit the page better.
4. For the editing page - call it "edit_message.php" - you need an HTML
form with a single, multi-row textarea input, so the manager can type
the page content. And the cool part is, you only have to build an EDIT
function, (not an insert or delete page, as there will always be page
content). For the form's action, send it via "POST" method to a .PHP
file named something like "update_page.php."
<pre>
<?
include("connect.php");
$query = "select * from table_name where message_id = '1'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo "<form name=\"form1\" method=\"POST\" action=\"update_page.php\">
<textarea name=\"message\" rows=\"5\">".$row["message"]."</textarea>
<input name=\"go\" type=\"submit\" value=\"Submit\">
</form>";
?>
</pre>
5. In "update_page.php," here's the code:
<pre>
<?
include("connect.php");
$query = "update table_name set message =
'".$HTTP_POST_VARS["message"]."' where message_id = '1'";
$result = mysql_query($query);
echo "<script>window.location=\"edit_message.php\"</script>";
?>
</pre>
The last line sends the manager back to the edit_message.php page.
It's "bare bones" code, and you'll want to password protect the
manager's editing page, so as to avoid anyone entering bad code and
really messing up your site. Hope that helps!
Powderfinger wrote:
> My client is asking me for a "WEBPAGE" where he can update a page on his
> website. In other words, he has a list on one of the pages which he wants to
> personally update without needing me everytime. I've been told I need to
> write a "php script", something I know little about, to generate a dynamic
> web-page. The hosting does support server-side php scripts and MySQL.
>
> Any suggestions? Does anyone know of any sample scripts which might do the
> job?
>
> Thanks
>
> Jack
Navigation:
[Reply to this message]
|