Are they going to be able to edit every page? In that case you may have to rearrange the site a little. For instance instead of multiple .htm files for the pages, you should have just one file, index.php, that gets the different pages like index.php?page=pagename.
It's really not that hard. First, you should divide your code into a header and a footer. There's usually a bunch of HTML that goes right up to the content- that's your header. Then all the HTML after the content, that's your footer.
Save those files as header.php and footer.php, and then your index.php can look something like this:
PHP Code:
<?php
include 'config.php';
include 'header.php';
if (!$_GET['page']) {$page = 'home';}
$sql = "SELECT content FROM pages WHERE title = '$page'";
$result = mysql_query($sql, $db);
if (mysql_num_rows($result) == 0)
{
die('Error.');
}
else
{
$row = mysql_fetch_array($result);
echo $row['content'];
}
include 'footer.php';
?>
The config.php file is just a standard file where you keep your database username and password.
Set up a database with a table called "Pages" with three fields: ID (primary key), title, and content.
You can still show your pages as .htm files, just put this .htaccess file in the root directory:
Code:
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine ON
##### Index Page Rules #####
RewriteRule ^(.*).htm index.php?page=$1
##### Deny .htaccess viewing #####
RewriteRule ^\.htaccess$ - [F]
Now, to let them edit each page, make a directory called "admin" or something and password-protect it with your cpanel. That's where you can put the page where they do the editing. That page can look something like this:
PHP Code:
<?php
include 'path_to_includes/config.php';
if ($_POST['submitok']) {$submit = true;}else{$submit = false;}
if ($_GET['edit']) {$page_to_edit = $_GET['edit'];}else{$page_to_edit = 'none';}
if ($_GET['save'] == 'ok') {$success = true;}
?>
<html>
<head>
<title>Your Control Panel</title>
<script language="javascript" type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "table, save, advhr, advimage, advlink, emotions, iespell, insertdatetime, preview, zoom, flash, searchreplace, print, contextmenu, paste, directionality, fullscreen",
theme_advanced_buttons1 : "bold,italic,underline, separator, strikethrough, ,sub,sup,charmap, separator, forecolor,backcolor, separator,justifyleft,justifycenter,justifyright, justifyfull, separator, bullist,numlist,separator, hr, separator, link,unlink, separator, cut,copy,paste",
theme_advanced_buttons2 : "image, anchor, cleanup, separator, undo, redo, separator, tablecontrols, separator, insertdate,inserttime, code, help",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "center",
theme_advanced_path_location : "bottom",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],div[style|align|class|id]"
});
</script>
</head>
<body bgcolor="#dedede" style="font-family:helvetica;font-size:10pt;">
<form method="post" action="">
<h1 align="center" style="color:navy;font-family:helvetica;">Your Website Control Panel</h1>
<?php
if ( ($submit == false) && ($page_to_edit == 'none') )
{
echo '<div align="center">';
if ($success)
{
echo '<font color="green"><b>';
echo 'Page edited successfully!';
echo '</b></font><br /><br />';
}
echo 'Choose a page to edit:<br /><br />';
echo '<a href="index.php?edit=home">Home</a><br />';
echo '<a href="index.php?edit=tournaments">Tournaments</a><br />';
echo '<a href="index.php?edit=big_pulls">Big pulls</a><br />';
echo '<a href="index.php?edit=photos">Photos</a><br />';
echo '<a href="index.php?edit=contact">Contact</a>';
echo '</div>';
}
elseif ( (!$submit) && ($page_to_edit != 'none') )
{
$sql = "SELECT content FROM pages WHERE title = '$page_to_edit'";
$result = mysql_query($sql, $db);
$row = mysql_fetch_array($result);
?>
<table width="600" align="center">
<tr>
<td>
<textarea style="width:650px;height:375px" name="text">
<?php echo $row['content']; ?>
</textarea>
</td>
</tr>
</table>
<div align="center">
<input type="submit" value="Save Changes" /><br /><br />
<a href="#" onclick="window.location=('index.php')">Cancel Edit</a>
</div>
<input type="hidden" name="submitok" value="ok" />
</form>
</body>
</html>
<?php
}
elseif ($submit)
{
$title = $_GET['edit'];
$text = $_POST['text'];
$sql = "UPDATE pages SET content = '$text' WHERE title = '$title'";
$result = mysql_query($sql, $db);
if ($result)
{
echo '<script>window.location=(\'index.php?save=ok\')</script>';
}
else
{
echo 'error.';
exit;
}
}
?>
The extra stuff in there is for TinyMCE, you don't have to use that of course, you could use a plain textarea if you want.
I had to do this for
this site last week, so I just thought I'd share my code, which I just threw together and is just very basic.