Location: PHPKode > projects > Helpdesk Over Web > how/sysmgmt/depts.php
<?php

// Depts List Admin

// Include Configuration File
require_once ('../includes/config.inc'); 

// Set the page title and include the HTML header.
$page_title = 'Helpdesk Over Web - Depts Admin';
include ('../includes/header.html');

if (isset($_POST['deptname'])) { // Check if the form has been submitted.
	// Connect to Database
	require_once ('../includes/mysql_connect.php');

	if (empty($_POST['deptname'])) {
		$newdept = FALSE;
		echo '<H4><font color="red">ERROR - Department Name not Specified.</font></H4>';
		echo "<P>[ <A HREF='config.php'>Configuration Menu</A> ]</P>";
		include ('../includes/footer.html');
		mysql_close();		
		exit();
	} else {
		$newdept = $_POST['deptname'];
		$query = "INSERT INTO depts (DeptName) VALUES ('$newdept');";		
		$result = mysql_query($query)
		   or die("Invalid query: " . mysql_error());
		mysql_close();
		header ('Location: /how/sysmgmt/depts.php');	
		exit();
}
} 

// Connect to Database
require_once ('../includes/mysql_connect.php');

// Execute query to retrieve user details.
$sql = 'SELECT * FROM `depts` ORDER BY DeptName;';
$records = range(1, 500);
$result = mysql_query($sql)
   or die("Invalid query: " . mysql_error());
$num_rows = mysql_num_rows($result);

// Output query results in a table.
echo ("<H1>System Settings</H1><H3>Departments Database</H3>");
echo ("<TABLE WIDTH='600'><TR><TD WIDTH='175'><b>Department Name</b></TD><TD><b>Click to Delete</b></TD></TR>");
while($i = mysql_fetch_row($result)) { 
	echo ("<TR>");
	echo ("<TD>$i[1]</TD>");
	echo ("<TD><A HREF='deletesetting.php?type=dept&id=$i[0]'>Delete</A></TD>");
	}
echo ("</TABLE>");
echo ("<H5>Add New Department</H5>");
echo "<FORM ACTION='depts.php' METHOD='post'><TABLE><TR><TD><b>Department Name</b>:</TD><TD><INPUT TYPE='text' LENGTH='52' MAXLENGTH='50' NAME='deptname'></TD></TR>";
echo "<TR><TD COLSPAN=2><input type='submit' name='submit' value='Add New Department' default></TD></TR></TABLE></FORM>";
echo "<P>[ <A HREF='config.php'>Configuration Menu</A> ]</P>";

// Include standard HTML footer
include ('../includes/footer.html');
mysql_close();
?>
Return current item: Helpdesk Over Web