Location: PHPKode > projects > ERPSOD > erpsod/dept_edit.php
<?PHP
include_once("config.php");

$form1=$_GET["form"];
$action=$_POST["command"];
$id=$_POST["deptlist"] ;

$tasktel=0;

if ($form1=="dept_edit"){

	if ($action == "Cancel") {
		header('Location: dept_list.php');
	} else{
		$id=$_POST["id"] ;
		$deptdesc = $_POST["deptdesc"] ;
		$error_txt = '';
		if ($deptdesc =="" ){
			$error_txt = "Department-name can not be blank";
		} else{
			if ($id==0){
				$sql = "select * from erpdept where upper(deptdesc)=upper('$deptdesc')" ;
				$result = mysql_query($sql);
				$num_rows = mysql_num_rows($result);

				if ($num_rows ==0){
					$sql="INSERT INTO erpdept (deptdesc) VALUES ( '$deptdesc')";
					$result = mysql_query($sql);
				}
			} else{
				$sql="UPDATE erptdept SET deptdesc='$deptdesc' WHERE deptid = $id";
				$result = mysql_query($sql);
			} 
		}
		header('Location: dept_list.php');
	}
} else {
	if ($form1<>"dept_list"){
		header('Location: dept_list.php');
	}
	if ($action == "New"){
		$id = 0;
		$deptdesc="";
	}
	if ($action == "Delete"){
		$sql="select * from erpuser where deptid=$id";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);
		if ($num_rows>0){
			die("dept is still in use and cannot be deleted");
		}
		$sql="delete from erpdept where deptid = $id";
		$result = mysql_query($sql);
		header('Location: dept_list.php');
	}
	if ($action == "Edit"){
		$sql="SELECT * FROM erpdept WHERE deptid = $id";
		$result = mysql_query($sql);
		$num_rows = mysql_num_rows($result);
		if ($num_rows <>0){
			$row = mysql_fetch_row($result);
			$id = $row[0];
			$deptdesc = $row[1];
		}
	}
}
?>
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="<?PHP echo $style ?>">
<script language="JavaScript1.2" src="js/coolmenus4.js">
</script>
</HEAD>
<body bgcolor="#ffffff">
<script language="JavaScript1.2" src="js/erpsod.js">
</script><br><br>
<center>
<h3>Departments</h3>
<?php
if ($error_txt <>""){
	echo $error_txt ;
	echo "<br>";
}
?>
<FORM ACTION="dept_edit.php?form=dept_edit" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="id" VALUE="<?php echo $id ?>">
<table border=0 cellpadding=4 cellspacing=0 bgcolor="AQUA"><tr><td>
<tr>
<td>Department name</td>
<td><Input Name="deptdesc" MaxLength="50" Size="50" Value="<?php echo $deptdesc ?>"></td>
</tr>
<br>
<br>
<tr>
<td colspan=2 align="center">
<?php if (role_check("Updater")) { ?>
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Submit">
<?PHP } ?>
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Cancel">
</td></tr>
</table>
</td></tr></table></center>
</FORM>
</BODY>
<?php
include_once("footer.php");
?>
</HTML>
Return current item: ERPSOD