Location: PHPKode > projects > PAT and Inventory Management System > m/a/checkout.php
	Pat and Inventory Management System
	Version 0.1
	Created by Tom Dyer
	Last edited by Tom Dyer 19/9/09
	Checkout Select Gig

	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';
	mysql_connect($sqlhost,$username,$password);						//connect to the database
	@mysql_select_db($database) or die( "Unable to select database");
	$query="SELECT * FROM gignames ORDER BY gig ASC";						//get a list of gigs
	$barcode = $_SESSION['barcode'];
	$name = $_SESSION['name'];
	<title> Check Out</title>
	<head><link rel="shortcut icon" href="<?php echo "$servroot"; ?>/favicon.ico" type="image/x-icon"><h4>Check an Item out to a Gig</h4></head>
	<body onLoad="document.input.barcode.focus()" LINK="0033CC" VLINK="0033CC"> <!-- Keep links blue after visit -->
		<table border="0">
		<!--<form action="input.php" method="post" name="input">-->
		<form action="" method="post" name="input">
		<input type="hidden" name="cmd" value="done"</input>
		<td>Barcode: </td><td><?php echo "$barcode" ?></td>
		<td>Description: </td><td><?php echo "$name" ?></td>
		</tr><tr><td>Select Gig: </td><td><SELECT id="gig" name="gig">
					<option value=pick>Choose Gig</option>
					<?php										//Put gig names in drop down list
						while ($i < $num) 
							echo '<option value="'.$gigs.'" ';
							echo '>'.$gigs.'</option>';
        <td>Quantity: </td><td><input name="quantity" id="quantity" value="1" size="2"></td>
		<td><input type="submit" value="Select Gig"></td>

	if($_POST['cmd'] == "done")		//Check if form has been submitted
		$gig = $_POST['gig'];
		$quantity = $_POST['quantity'];
		if($gig == "pick")
			echo "Please select a gig";
			$bsearch = mysql_query("SELECT * FROM gigs WHERE barcode='$barcode'");	//collect information on selected barcode
			while($row = mysql_fetch_array($bsearch))	//Start While Loop
				$bref=$row['ref'];	//Set variables from database record
					if($bgig == $gig) //check we are looking at the gig we want.
						$quantity = $bquantity + $quantity;
						mysql_query("UPDATE gigs SET quantity = '$quantity' WHERE ref = '$bref'"); //Update gig to database
						echo "$name added to the gig";
						$done = 1;
			if(empty($row) && empty($done))
				mysql_query("INSERT INTO `gigs` VALUES ('', '$gig', '$barcode', '$quantity', '')");	//Add gig to database
				echo "$name added to the gig";
			echo '<script language="javascript">window.location="index.php";</script>';

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