Location: PHPKode > projects > PAT and Inventory Management System > m/a/add_pat.php
	Pat and Inventory Management System
	Version 0.1
	Created by Tom Dyer
	Last edited by Tom Dyer 12/9/09
	Inventory - Add an Item
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'];
$seluser = $_SESSION['returnuser'];	//if it has not, use the session variable for pre-selected user

mysql_connect($sqlhost,$username,$password);						//connect to the database
	@mysql_select_db($database) or die( "Unable to select database");
	$query="SELECT * FROM users ORDER BY name ASC";						//get a list of users
	<title>PIMS | Add an Item & Log Test</title>
	<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h4>Add an Item and Test to the Database</h4></head>
	<body onLoad="document.input.name.focus()" LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
		<table border="0"> <!-- Table to make the form look nice -->
		<form action="" method="post" name="input"> <!-- Form that will submit data back to this file -->
		<input type="hidden" name="cmd" value="done"</input>
		<td>Barcode: </td><td><?php echo "$barcode"; ?></td>
		<td>Item Description: </td><td><input id="name" name="name" value = "<?php echo "$name"; ?>"/></td>
		<td>Retest Period: </td><td><input id="retest" name="retest" size="2" value="1"> Year(s)</td>
		<td>Tested By: </td><td><SELECT id="user" name="user"><option value=pick>Choose Name</option><?php
														while ($i < $num) {
														echo '<option value="'.$names.'" ';
															if ($names == $seluser){
															echo ' selected="selected"';
															} else {}
														echo '>'.$names.'</option>';
														?></select></td><!-- Name feild in the form of a drop-down-box. Names found via SQL, and the last entered name is remembered so remains selected. -->
		<td>Test Date<small>(Y-M-D)</small>: </td><td><input id="date" name="date" value="<?php echo date("Y-m-j"); ?>"/></td><!-- Date Feild. Date auto-fills with the current. -->
		<td><input type="submit" value="Submit"></td>
		</form> <!-- Close of Input Form -->
		</table> <!-- Close of Form Table -->

	if ($_POST['cmd'] == 'done') { //check if the form has been submitted
		$name = $_POST['name']; //set variables
		$retest = $_POST['retest'];
		$user = $_POST['user'];
		$date = $_POST['date'];
		$barcode = (int)$barcode; // Format out any leading zeros and/or text
		if(empty($name)) // Check for a Description
				echo "Please enter a Description";
				echo '<br><hr width="100%" /><a href="index.php">Back</a><br>';
		if($user == 'pick') // Check if user has entered a name
				echo "Please select your Name"; // Tell them what they did wrong
				echo '<br><hr width="100%" /><a href="index.php">Back</a><br>'; //Navigation Options
				die; //Stop
		@mysql_select_db($database) or die( "Unable to select database"); // Connect to the database to check for a previous record
		$data = mysql_query("SELECT * FROM equipment WHERE barcode='$barcode'");
		while($row = mysql_fetch_array($data))
		if(empty($gotname)) // check for an existing record
				$newdate=$date;	// Data adjust (if required)
				@mysql_select_db($database) or die( "Unable to select database");
				mysql_query("INSERT INTO `equipment` VALUES ('$barcode', '$name', '$retest', '$newdate', '$user')"); // Enter new information into the Database
				echo "$name has been successfully added to the database."; // Tell the user it worked
				echo '<br><hr width="100%" /><a href="..">Back</a><br><a href="../../../">Home</a><br>'; // Give them navigation
				echo '<script language="javascript">window.location="index.php";</script>';
				die; // Stop

		<br><hr width="100%" /><a href="index.php">Back</a><br>
Return current item: PAT and Inventory Management System