<?php
session_start();
$login=mysql_connect("localhost","root","");
mysql_select_db("bookstore",$login);
include("connect.php");

$j = $_POST['counter'];

$ISBN = $_POST['ISBN'];
$quantity = $_POST['quantity'];

	$query = "SELECT * FROM item WHERE ISBN = '$ISBN'";
	$result = $db->query($query);
	$row = $result->fetch_array();
	$num_results = $result->num_rows;
	
$itemQuantity = $row['itemQuantity'];

if($quantity<=0){
echo "<script language='javascript'>alert('Please check your amount.')</script>";
echo "<script language='javascript'>window.location='parent.php'</script>";
}else{
	$quantity = $quantity + $itemQuantity;
	$query2 = "UPDATE item SET itemQuantity = '$quantity' WHERE ISBN = '$ISBN'";
	$result2 = $db->query($query2);
	
	$query=mysql_query("delete from receivedinvitem WHERE ISBN!=0");
	
}
	$db->close();
	echo "<script language='javascript'>alert('$ISBN has $quantity now.')</script>";
	echo "<script language='javascript'>window.location='parent.php'</script>";
	
?>