Location: PHPKode > projects > bloggeruniverse > categories.php
<?php
ob_start();
session_start();
include("includes/config.php");
require_once("theme.php");
$page->settitle("Administration :: Categories");
$page->output();
if (($logged[username]) && ($logged[level] == 5))
{
	switch($_GET[op])
	{
		case "addcat":
		if (!$_POST['submit'])
		{
		?>
		<form action="" method="post">
		<h1>Add article category</h1>
		<h2>category Name</h2>
		<input name="name" type="text"><br />
		<p><input type="Submit" value="Submit" name="submit"></p>
		</form>
		<?php
		}
		else
		{
			$name = htmlspecialchars($_POST[name], ENT_QUOTES);
			mysql_query("INSERT INTO category (name) VALUES ('$name')")or die(mysql_error());

			echo 'Category Successfully added! <a href="admin.php">Go back to admin home page</a>';
		}
		break;
		case "editcat":
		if (!$_POST['submit'])
		{
			if (((!isset($_GET['id'])) || (trim($_GET['id']) == '')))
			{
				$query = mysql_query("SELECT * from ".PREFIX."category");
				while ($result = mysql_fetch_assoc($query))
				{
					echo "<a href=\"?op=editcat&amp;id=".$result[id]."\">Edit $result[name]</a><br />";
				}
			}
			else if ($_GET[id])
			{
				$id = $_GET['id'];
				$result = mysql_query("SELECT * FROM ".PREFIX."category WHERE id = '$id'") or die (mysql_error());
				if (mysql_num_rows($result) > 0)
				{
					$row = mysql_fetch_assoc($result);
				?>
				<form action="" method="POST">
				<h1>Edit Catagoy #<?php echo $id; ?></h1>
				<input type="hidden" name="id" value="<?php echo $id; ?>">
				<h2>Name</h2>
				<input value="<?php echo stripslashes($row[name]); ?>" name="name" type="text" size="50"><br>
				<p>
				<input name="submit" type="Submit" value="Submit">
				<input type="reset">
				</p>
				</form>
				<?php
				}
				else
				{
					echo 'News item not found!';
				}
			}
		}
		else
		{
		$name = mysql_real_escape_string($_POST[name]);
		$result = mysql_query("UPDATE category SET name = '$name' WHERE id = '".$_POST[id]."'")or die(mysql_error());
		echo 'Category successfully edited. <a href="admin.php">Go back to admin home page</a>';
		}
		break;
		case "deletecat":
		if (((!isset($_GET['id'])) || (trim($_GET['id']) == '')))
		{
			$query = mysql_query("SELECT * from ".PREFIX."category");
			while ($result = mysql_fetch_assoc($query))
			{
				echo "<a href=\"?op=deletecat&amp;id=".$result[id]."\">Delete $result[name]</a><br />";
			}
		}
		else if ($_GET[id])
		{
			$id = $_GET['id'];
			$query1 = mysql_query("SELECT * from ".PREFIX."category where id = '$id'");
			$result1 = mysql_fetch_assoc($query1) or die(mysql_error());
			$result = mysql_query("DELETE FROM ".PREFIX."category WHERE id = '$id'") or die(mysql_error());
			$result = mysql_query("DELETE FROM ".PREFIX."blog WHERE category = '$result1[name]'") or die(mysql_error());
			$result = mysql_query("DELETE FROM ".PREFIX."blog_comments WHERE category = '$result1[name]'") or die(mysql_error());
			echo 'Category records, blog records and Comment records successfully deleted. 
		<a href="admin.php">Go back to admin home page</a>';
		}
		break;
		default:
		echo "<a href=\"?op=addcat\">Add Category</a><br />
		<a href=\"?op=editcat\">Edit Category</a><br />
		<a href=\"?op=deletecat\">Delete Category</a>";
		break;
	}
}
else
{
echo NOT_ADMIN;
}
$content->output();
$close->output();
?>
Return current item: bloggeruniverse