| | |||||
| ||||||||
| CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| New Member Join Date: Jan 2007
Posts: 17
![]() | 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> ????: NamePros.com http://www.namepros.com/code/303871-php-code-inventory-system-updating-item.html </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. |
| |
| | #2 (permalink) |
| is on hiatus Join Date: May 2006
Posts: 2,449
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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());
__________________ Currently on hiatus. Back whenever. |
| |
| | #5 (permalink) |
| NamePros Regular Join Date: May 2004 Location: NYC
Posts: 236
![]() ![]() ![]() | Ack! Never trust user input (e.g., $_POST and $_GET variables). The above code is open to a sql injection. Replace PHP Code: PHP Code: PHP Code: |
| |