Location: PHPKode > projects > PAT and Inventory Management System > m/a/modify.php
<!--
	Pat and Inventory Management System
	Version 0.2
	Created by Tom Dyer
	Last edited by Tom Dyer 12/9/09
	Modify Item - PHP
-->

<?php
	session_start();	// This connects to the existing session. Allows sharing of variables between pages for a smoother user experience
$directory = $_SESSION['docroot'];
include_once '../../config.php';	
	$barcode=$_SESSION['barcode'];
	$barcode= (int)$barcode; 	// Remove text and/or leading zeros
	if(empty($barcode))
			{
				echo "Please enter a barcode";
				echo '<br><hr width="100%" /><a href="index.php">Back</a><br>';
				die;
			}
	mysql_connect($sqlhost,$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
    $result = mysql_query("SELECT * FROM equipment WHERE barcode='$barcode'");

while($row = mysql_fetch_array($result))
  {
  $gotref=$row['barcode'];
  $gotname=$row['name'];
  $gotretest=$row['retest'];
  $gotuser=$row['user'];
  $gotdate=$row['date'];
  }
  

$userquery="SELECT * FROM users ORDER BY name ASC";
$userresult=mysql_query($userquery);

$usernum=mysql_numrows($userresult);  
  	

if(empty($gotname))
	{
		echo "Barcode does not exist in Database.";
		echo ' <a href="/inventory/add/">Add Item</a>';
		echo '<br><hr width="100%" /><a href="index.php">Back</a><br><a href="../../../">Home</a><br>';
		die;
	}

?>

<html>
	<title>PIMS | Modify Item</title>
	<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h3>Modify Item</h3></head>
<body onLoad="document.input.name.focus()" LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
	
	<table border="0">
	<form action="" method="post" name="input">
	<input type="hidden" name="barcode" value="<?php echo "$barcode"; ?>"/>
	<input type="hidden" name="ent" value="done"/>
	<tr>
	<td>Barcode: </td><td><?php echo "$barcode"; ?></td>
	</tr><tr>
	<td>Description: </td><td><input type="text" name="name" value="<?php echo "$gotname"; ?>"/></td>
	</tr><tr>
	<td>PAT Required: </td><td><input type="checkbox" name="pat" value="pat" <?php if(empty($gotretest))
																					{
																					}
																					else
																					{
																					echo "checked";
																					}
																					?>></td> <!-- Checkbox. add 'checked' to auto-check the box -->
	</tr><tr>
	<td>Retest Period: </td><td><input type="text" name = "retest" size="2" value="<?php echo "$gotretest"; ?>"/> Year(s)</td>
	</tr><tr>
	<td>Tested By: </td><td><input type="text" name="user" value="<?php echo "$gotuser"; ?>"/></td>
	</tr><tr>
	<td>Test Date: </td><td><input type="text" name = "date" value="<?php echo "$gotdate"; ?>"/></td>
	</tr><tr>
	<td><input type="submit" name = "submit" value="Change Item"></td>
	</tr>
	</form> 
	</table>
	
<?php
	if($_POST['ent'] == 'done')
	{
		$barcode=$barcode;	//set variables from previous form
		$name=$_POST['name'];
		$retest=$_POST['retest'];
		$user=$_POST['user'];
		$date=$_POST['date'];
		$pat=$_POST['pat'];
	
		if(empty($name))
		{
			echo "<br>ERROR! Please try again";
			echo '<br><hr width="100%" /><a href="index.php">Back</a><br>';
			die;
		}
		
		if(empty($retest)) // of there is an empty retest field, then remove any PAT data
		{
			$retest= '';
			$user= '';
			$date= '';
		}
		if($pat == 'pat')
		{}
		else
		{
			$retest= '';
			$user= '';
			$date= '';
		}
		
		mysql_query("UPDATE equipment SET name = '$name' WHERE barcode = '$barcode'");
		mysql_query("UPDATE equipment SET retest = '$retest' WHERE barcode = '$barcode'");
		mysql_query("UPDATE equipment SET user = '$user' WHERE barcode = '$barcode'");
		mysql_query("UPDATE equipment SET date = '$date' WHERE barcode = '$barcode'");
		
		mysql_close();
		
		echo "<br>Edited Entry";
		echo '<script language="javascript">window.location="index.php";</script>';
	}
	?>
	<br><hr width="100%" /><a href="index.php">Back</a><br>

	
</body>
</html>
Return current item: PAT and Inventory Management System