Location: PHPKode > projects > PAT and Inventory Management System > m/a/retire.php
	Pat and Inventory Management System
	Version 0.1
	Created by Tom Dyer
	Last edited by Tom Dyer 14/9/09
	Remove item 3 (2)

	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'];	//Set variables from previous page's form
	$name = $_SESSION['name'];
	$date = date("Y-m-j");
	mysql_connect($sqlhost,$username,$password);						//connect to database
	@mysql_select_db($database) or die( "Unable to select database");
	$rbarcode = "r".$barcode;	//append barcode with a 'r'
	$unique = 0;		//set variable for uniqueness check
	while ($unique < 1)	//Start while loop
		$rsearch = mysql_query("SELECT * FROM equipment WHERE barcode='$rbarcode'");	//get record data from database
		$row = mysql_fetch_array($rsearch);	
		$gotbarcode=$row['barcode'];	//set variables from database output
		if(empty($gotname))	//check if barcode already exists
			$unique++;	//if barcode is spair, exit loop
			$rbarcode = "r".$rbarcode;	//add an extra 'r' to the barcode
	}	//close while loop

<title>PIMS | Remove Item</title>
<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h3>Confirm Deletion of Item</h3></head>
<body LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
		The Item will no longer be PAT Testable, and the barcode can be reused.
		<table border="0">
		<form action="" method="post" name="input">	
		<input type="hidden" name="ent" value="done">
		<td>Barcode: </td><td><?php echo "$barcode"; ?></td>
		<td>Description: </td><td><?php echo "$name"; ?></td>
		<td><input type="submit" value="Confirm Remove Item"></td>

	if($_POST['ent'] == 'done')	//check if form is submitted
		$retsearch = mysql_query("SELECT * FROM equipment WHERE barcode='$barcode'");	//get record data from database
		$retrow = mysql_fetch_array($retsearch);	
		$retbarcode=$retrow['barcode'];	//set variables from database output
		$rbarcode = $rbarcode;
		mysql_connect(localhost,$username,$password);	//connect to database
		@mysql_select_db($database) or die( "Unable to select database");
		mysql_query("DELETE FROM equipment WHERE barcode='$barcode'");	//delete old information
		mysql_query("INSERT INTO `equipment` VALUES ('$rbarcode', '$retname', '$retretest', '$date', '$retuser')"); // Enter new information into the Database
		echo "Item removed from the Database. The barcode may now be reused. <br>";
		echo '<script language="javascript">window.location="index.php";</script>';

<body LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
<br><hr width="100%" /><a href="index.php">Back</a><br>
Return current item: PAT and Inventory Management System