<?php
session_start();
$ISBN = $_POST['ISBN'];
$poNo = $_POST['poNo'];
if($_POST["Submit"] == "Submit")
{
	include("connect.php");

	$result = mysql_query("SELECT * FROM poitem WHERE poItem = '$ISBN'&&poNo = '$poNo'");
	
	$num_results = mysql_num_rows($result);

if($num_results>0){
echo "<script language='javascript'>alert('You already add this item.')</script>";
echo "<script language='javascript'>self.close();</script>";
}else{
	include("connect.php");
	$result2 = mysql_query("INSERT INTO poitem(poItem,poNo) VALUES ('$ISBN', '$poNo')";
	
	
	echo "<script language='javascript'>alert('Insert $ISBN $poNo')</script>";
	echo "<script language='javascript'>self.close();</script>";
}
}
?>

<html>
<head>
<title>Item Selection Page</title>
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onunload="opener.location.reload();">

<?php
include("connect.php");
$po = $_GET['po'];
$result = mysql_query("SELECT * FROM item ORDER BY itemName";   

$num_results = mysql_num_rows($result);

echo "<table border='1' cellpadding='0' cellspacing='0' width='100%'>";

echo "<tr>";
echo "<td colspan='4'>";
echo "Item List";
echo "</td>";
echo "</tr>";

for ($i=0; $i <$num_results; $i++){

$row = mysql_fetch_array($result);
echo "<form name='form' method='post'>";
echo "<tr>";
echo "<td>";
echo $i+1;
echo "</td>";
$num = $i+1;
echo "<td>";
echo "<input type='hidden' name='ISBN' value='$row[ISBN]'>".$row['ISBN']."";
echo "</td>";

echo "<td>";
echo "<input type='hidden' name='itemName' value='$row[itemName]'>".$row['itemName']."";
echo "</td>";

echo "<td>";
echo "<input type='hidden' name='poNo' value='$po'><input type='submit' value='Submit' name='Submit'>";
echo "</td>";
echo "</tr>";
echo "</form>";
}

echo "</table>";
?>
</html>
