Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Php code for inventory system in updating item quantity

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Namecheap AuctionsNamecheap Auctions
Watch

cotton

Established Member
Impact
0
:(

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..

i stored the cart in the database..

Anyone..help me pls..i need the code so badly.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You can add upon checkout.
Here's just a sample of what you want to use...
Code:
$item = $_GET['item']

$result = mysql_query("SELECT * FROM inventory
 WHERE item='$item'") or die(mysql_error());  

$row = mysql_fetch_array( $result );

$count = $row['count'] - 1;

$result = mysql_query("UPDATE inventory SET count='$count' WHERE item='$item'") 
or die(mysql_error());
 
0
Close
thank u very much!! i will try that on..
 
0
Close
how to show the item in the cart?
 
0
Close
Ack! Never trust user input (e.g., $_POST and $_GET variables). The above code is open to a sql injection.

Replace
PHP:
$item = $_GET['item'];
with
PHP:
$item = mysql_real_escape_string($_GET['item']);

Also, you might want to check if the item actually exists, and if you have any in stock:
PHP:
$row = mysql_fetch_array( $result );

if ($row === false)
{
        echo 'this item does not exist!';
        return; // or whatever you need to do
}
else
{
        if ($row['count']  == 0)
        {
             echo 'sorry, none in stock.';
             return; // or whatever you need to do
        }

        // if you got here you have stock on hand, so continue
        $count = $row['count'] - 1;
        // etc...
}
Just a rough draft, but you get the idea.
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back