This is the code I'm using.
<?php
session_start();
if(!$_SESSION['username']){
header('Location: ../login.php');
} else {
include_once '../functions/index.php';
$sql = "SELECT * FROM pages;";
$result = mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas"
});
</script>
<style type="text/css">
.button {
border: 1px solid #006;
background: #9cf;
}
</style>
</head>
<body>
<?php
if($_POST['updatePost'])
{
$id;
$content;
$id = $_POST['id'];
$content = $_POST['content'];
mysql_query("UPDATE pages SET content='$content' WHERE id='$id'");
exit;;
}
if($_POST['edit'])
{
$id = $_POST['id'];
$sql = "SELECT * FROM pages WHERE id='$id'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
?>
<form method="post">
<fieldset style="width:500px;">
<legend>Front Page</legend>
<table>
<tr>
<td width="20%"><label>Title:</label></td>
<td><?php echo $row['title'] ?></td>
</tr>
<tr>
<td width="20%" valign="top"><label>Content: </label></td>
<td><textarea rows="30" cols="60" name="content" /><?php echo $row['content'] ?></textarea></td>
<input type="hidden" name="id" value="' . $row['id'] . '" />
</tr>
<tr>
<td></td><td align="center"><input type="submit" name="updatePost" id="updatePost" value="Update Post" style="width:200px;" class="button"/></td>
</tr>
</table>
</fieldset>
</form>
<?php
exit;
}
}
?>
<form method="post">
<p>Edit content by entering number
<input type="text" name="id" id="id" style="width:30px" />
<input type="submit" name="edit" id="edit" value="Edit" class="button"/>
</p>
</form>
<?php
echo '<table';
while($row=mysql_fetch_array($result))
{
echo '<tr>
<td width="50">Title:</td>
<td width="400">' . $row['title'] . '</td>
<td>' . $row['id'] . '</td>
</tr>';
}
echo '</table>';
?>
</body>
</html>
<?php
}
?>