<?php require_once('open_connection.php');?>
<link href="css/gridtable.css" rel="stylesheet" type="text/css" />
<body bgcolor="black">
<?php
 					
				$item_id = $_GET['item_id'];
                    $edit_query=mysql_query("SELECT  tbl_dir_fnb_quotation.quotation_id,tbl_dir_fnb_item.item_id, tbl_dir_fnb_item.item_description,tbl_dir_fnb_item.item_qty,
					                        tbl_dir_fnb_item.item_unit_price,tbl_dir_fnb_item.item_total
                                            FROM tbl_dir_fnb_quotation
                                            LEFT JOIN tbl_dir_fnb_item ON tbl_dir_fnb_quotation.quotation_id = tbl_dir_fnb_item.quotation_id where  tbl_dir_fnb_item.item_id='$item_id'")or die(mysql_error());
					 
                    $row1=mysql_fetch_array($edit_query);
                    $item_id=$row1['item_id'];
					$quotation_id=$row1['quotation_id'];
					
                ?>
				<h2>Add item_id to <?php echo  $item_id?><?php echo $quotation_id?></h2>
		<?php 
			   $item_id = $_REQUEST['item_id'];
			   $result1 = mysql_query("SELECT  tbl_dir_fnb_quotation.quotation_id,tbl_dir_fnb_item.item_id, tbl_dir_fnb_item.item_description,tbl_dir_fnb_item.item_qty,
					                        tbl_dir_fnb_item.item_unit_price,tbl_dir_fnb_item.item_total
                                            FROM tbl_dir_fnb_quotation
                                            LEFT JOIN tbl_dir_fnb_item ON tbl_dir_fnb_quotation.quotation_id = tbl_dir_fnb_item.quotation_id where  tbl_dir_fnb_item.item_id=".$item_id);  
		     while($row = mysql_fetch_array($result1))
		{
		?>
		<form method="post">
		<table width="56%" style="margin-top:15%" align="center" class="gridtable">
            <tr >
              <td width="616"><div align="center"><strong>Description</strong></div></td>
              <td width="64"><div align="center"><strong>Quantity</strong></div></td>
              <td width="84"><div align="center"><strong>Unit Price</strong></div></td>
            </tr>
            <tr>
              <td><div align="center">
                <input type="text" size="100" maxlength="80" name="item_description" value="<?php echo  $row['item_description']; ?>">
              </div></td>
              <td><div align="center">
                <input type="text" size="5" maxlength="10" name="item_qty" value="<?php echo  $row['item_qty']; ?>">
              </div></td>
              <td><div align="center">
                <input type="text" size="10" maxlength="10" name="item_unit_price" value="<?php echo  $row['item_unit_price']; ?>">
              </div></td>
            </tr>
          </table>
		            
						
					<tr><td colspan=2><center><button name="save" class="button">Update</button> &nbsp;<button name="save" on class="button">Back</button>
					</center></td></tr>
			 </fieldset>
                </form>
            </div>
        </div>

<?php } ?>
<?php
                if (isset($_POST['save'])){

                    $item_description=$_POST['item_description'];
                            $item_qty=$_POST['item_qty'];
					 $item_unit_price=$_POST['item_unit_price'];
					 $item_total=$item_qty*$item_unit_price;
                

                    $result3=mysql_query("update tbl_dir_fnb_item set item_description='$item_description',
                        item_qty='$item_qty',
                        item_unit_price='$item_unit_price',
                        item_total='$item_total'
                        where item_id='$item_id' ")or die(mysql_error());
				
		 
		 if ($result3){
		 		echo "<script language='javascript'>window.location='quotation_addOrder_zerogst.php?quotation_id=$quotation_id'</script>";}
			else{
				echo 'Unsuccessful, please try again';}
    }     
            ?>
</body>
