<?php
include 'dbc.php';
session_start();

$userid=$_SESSION["userid"];
$today=date("Y-m-d");


$size = count($_POST['obt_mark']);

$i = 0;
while ($i < $size) {
	$obt_mark= $_POST['obt_mark'][$i];
	$id = $_POST['id'][$i];
	
	$book_name= $_POST['book_name'][$i];
	
	 $sqlcus = "select * from inventory where book_name='$book_name'";
   $std_ledger=mysql_query($sqlcus) or die("Error : " . mysql_error());
   $app=mysql_fetch_array($std_ledger);
    
	$prebal=$app["balbook"];
	
	
 	$newbalbook=$prebal + $obt_mark;
	$query = "UPDATE inventory SET balbook='$newbalbook' WHERE id='$id'";
mysql_query($query) or die ("Error in query: $query");
	$sql3 = "Insert into pbook (id,date,book_name,qty,user_id) values (null,'$today','$book_name','$obt_mark','$userid')";
mysql_query($sql3) or die("Error : " . mysql_error());
	++$i;

// do the update and print out some info just to provide some visual feedback



} 
echo "Record Update";
?>
<a href="purchase.php"> Back </a>