home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Practical Internet Web Designer 89
/
PIWD89.iso
/
pc
/
CONTENTS
/
DEVELOPER
/
TUTORIAL_FILES
/
Pages90-91
/
admin
/
edit.php
< prev
next >
Wrap
PHP Script
|
2003-11-23
|
3KB
|
111 lines
<?php
//connect to the database
$conn = mysql_connect("localhost","root","pwd");
//choose the cms db
mysql_select_db("cms", $conn);
if ($_POST['btnEdit'] != "")
{
//update the content
$sql = "UPDATE tblContent SET contentTitle = '" . $_POST['contentTitle'] . "', contentText = '" . $_POST['contentText'] . "', catID = " . $_POST['catID'] . " WHERE contentID = " . $_POST['contentID'];
if (mysql_query($sql, $conn))
{
$updated = true;
}
}
if ($_GET['edit'] == "true")
{
$edit = true;
//get the content
$article = mysql_query("SELECT contentTitle,contentText ,catID FROM tblContent WHERE contentID = " . $_GET['contentID'], $conn);
while ($articlerow = mysql_fetch_array($article)) {
$title = $articlerow['contentTitle'];
$content = $articlerow['contentText'];
$catID = $articlerow['catID'];
//query the database for a list of categories - for the navigation menu
$result = mysql_query("SELECT catID, catName, catDesc FROM tblCat", $conn);
}
}
else
{
//query the database for a list of content
$result = mysql_query("SELECT contentID, contentTitle FROM tblContent ORDER BY contentTitle", $conn);
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CMS Admin</title>
<link rel="stylesheet" type="text/css" href="../global.css" />
</head>
<body>
<div id="banner">
<p> </p>
</div>
<div id="navigation">
<ul class="main">
<li><a href="add.php">Add Content</a></li>
<li><a href="edit.php">Edit Content</a></li>
</ul>
</div>
<div id="content">
<h1>Edit Content</h1>
<?php
if($edit == true)
{
?>
<form method="post" action="edit.php">
<p>Title:
<br /><input name="contentTitle" id="contentTitle" class="text" value="<?=$title?>" /></p>
<p>Content:
<br /><textarea name="contentText" id="contentText" class="largeText"><?=$content?></textarea></p>
<p>Category:
<br /><select name="catID" id="catID">
<?php
while ($row = mysql_fetch_array($result)) {?>
<option value="<?=$row['catID']?>"<?php
if ($row['catID'] == $catID)
{
print " selected=\"selected\"";
}
?>><?=$row['catName']?></option>
<?php
}
?>
</select></p>
<input type="hidden" name="contentID" id="contentID" value="<?=$_GET['contentID']?>" />
<p><input type="submit" name="btnEdit" value="Update Item" class="submit" /></p>
</form>
<?php
}
else
{
?>
<p>Select the content you wish to edit from the list below by clicking on the title.</p>
<ul>
<?php
while ($row = mysql_fetch_array($result)) {
print("<li><a href=\"edit.php?edit=true&contentID=" . $row[contentID] . "\">" . $row[contentTitle] . "</a></li>\n");
}
?>
</ul>
<?php
}
?>
</div>
</body>
</html>