Php code for inventory system in updating item quantity

SpaceshipSpaceship
Watch

cotton

Established Member
Impact
0
[RESOLVED]php code for inventory system in updating item quantity

recently,im developing an inventory system. the problem is i still dont know how to automatically update the quantity in the stock after the user take the items and how to add the item to the cart as in a shopping cart system. pls help..im using easyphp and i do not use class and function in my system.help me pls...

this is the sample of my code:
<table width="80%" border="1" align="center" cellpadding="0" cellspacing="1" bordercolor="#CCCCCC">
<tr>
<td width="18%" bgcolor="#E0E2EB"><div align="left">Description : </div></td>
<td width="82%"><? echo $row['description']; ?></td>
</tr>
<tr>
<td bgcolor="#E0E2EB"><div align="left">Item Code : </div></td>
<td><? echo $row['item_code']; ?></td>
</tr>
<tr>
<td bgcolor="#E0E2EB"><div align="left">Category : </div></td>
<td><? echo $row['category']; ?></td>
</tr>
<tr>
<td bgcolor="#E0E2EB"><div align="left">Current quantity : </div></td>
<td><? echo $row['quantity']; ?></td>
</tr>
<tr>

<td bgcolor="#E0E2EB">Required quantity : </td>
<td><input type="text" name="quantity" value="<? echo $row['quantity']; ?>">
<input type="hidden" name="id" value="<? echo $row['quantity']; ?>"></td>

</tr>



</table>


thnx in advance..
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
first, what exactly is the difference between

quantity
co_qty
c_qty
 
0
•••
quantity = the current quantity in the stock
c_qty = the amount of quantity user wants to take
co_qty=quantity left after the items has been taken

So, my algorithm is..

quantity - c_qty = co_quantity.

then, to update the table stationary for quantity in the stock...i do this: co_qty = quantity.

is it wrong?
 
0
•••
ok, now I get it. The variable names were very confusing. So...why do you need both $co_qty and $quantity? In the database, all you need to store is how much stock you have on hand, right? When the user requests a quantity, you subtract that from what's in stock, and then update the database to show the new, reduced quantity.

It seems that you're only updating $co_qty in the database, but you're also retrieving --and trying to use-- $quantity, which never seems to change.

So I don't think you need $quantity at all, anywhere. You can just use:
PHP:
if ($c_qty > 0 && $co_qty > 0 && $c_qty <= $co_qty)
{
mysql_query( "UPDATE `stationary` SET `co_qty` = $co_qty-$c_qty, `description` = '$description', category = $category WHERE`item_code` = $id LIMIT 1") or die(mysql_error()); 
}
 
0
•••
PHP:
View.php

 <td><form name="form1" method="post" action= "check_arrival.php">
                                  <table width="70%"  border="0" align="center" cellpadding="0" cellspacing="0">
                                    <tr>
                                      <td width="82%"><div align="center">
                                        <p>
										
                                <table width="80%"  border="1" align="center" cellpadding="0" cellspacing="1" bordercolor="#CCCCCC">
                                  <tr>
                      <input type="hidden" name="id" value="<? echo $row['id']; ?>" /> 
<input type="hidden" name="item_code" value="<? echo $row['item_code']; ?>" /> 
<input type="hidden" name="description" value="<? echo $row['description']; ?>" /> 
<input type="hidden" name="quantity" value="<? echo $row['quantity']; ?>" /> 
<input type="hidden" name="category" value="<? echo $row['category']; ?>" /> 
<input type="hidden" name="co_qty" value="<? echo $row['co_qty']; ?>" />  
                                              <tr>
                                    <td bgcolor="#E0E2EB">Required Quantity  : </td>
                                    <td><input name="c_qty" type="text" id="c_qty" size="10" maxlength="10"></td>
                                  </tr>

PHP:
check_arrival.php

<?
$item_code = $_POST['item_code'];
$description = $_POST['description'];
$category = $_POST['category'];
$quantity = $_POST['quantity'];
$c_qty = $_POST['c_qty'];


$insert = "INSERT INTO stationary (item_code, description, category, c_qty) 
			VALUES ($item_code, $description, $category, $c_qty, )";
			
?>
<form method="post" action="../user/dbView_Item.php"">
 
  <Input name="item_code" value="<? echo $item_code; ?>" type=hidden>
  <Input name="description" value="<? echo $description; ?>" type=hidden>
  <Input name="category" value="<? echo $category; ?>" type=hidden>
  <Input name="quantity" value="<? echo $c_qty; ?>" type=hidden>

  <h2><font color="blue" size="4">Confirm Item Taken</font></h2>

<?

echo"<tr>";
echo "<td>Item code:</td><td><b>$item_code</b></td>";
echo"<tr>";
echo "<td>Description:</td><td><b>$description</b></td>";
echo"<tr>";
echo "<td>Category:</td><td><b>$category</b></td>";
echo"<tr>";
echo "<td>Quantity:</td><td><b>$c_qty</b></td>";
echo"</tr>";
?>
<br>
If your input is correct, please click the button below. Otherwise, <a href="javascript:history.back()">go back</a> to correct changes.<br><br>
<input type="submit" name="Submit" value="Take this material ">

PHP:
dbView_Item.php
<?
$quantity = $_POST['quantity']; 
$category = $_POST['category'];
$c_qty = $_POST['c_qty'];
$description = $_POST['description'];
$item_code = $_POST['item_code']; 
						 
 if ($c_qty > 0 && $quantity > 0 && $c_qty <= $quantity) 
{ 
mysql_query( "UPDATE `stationary` SET `quantity` = $quantity-$c_qty, `description` = '$description', category = $category WHERE`item_code` = $item_code LIMIT 1") or die(mysql_error());  
}

echo "<SCRIPT>alert('Item has been taken')</script>";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=Home.php\">"; ?>

I dont know why, the output says undefined index c_qty although i did retrieve it. and the quantity didnt update also..is there any codes that i'd forgotten or misplaced?

my table stationary in the database includes these variables:item_code primary key, description, category, quantity and ct_qty.

hey, i did it! the quantity is updated...i should put the sql update in the check_arrival.php and not sql insert...btw, ur algorithm works...thankss..i dont know how to repay u..thanks a lot!!!
 
0
•••
excellent! Glad it worked out.
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy — Payment Flexibility
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back