2014-10-30 2 views
0

Я создаю систему управления запасами, и я не могу понять, как связать таблицу инвентаря с таблицей продаж, чтобы продукты в таблице инвентаря обновлялись при продаже. Я использую MySqlКак обновить таблицу акций после совершения продажи

Вот проданный.php. Когда я продаю продукт на этой странице, сохраните запись в таблице продаж, но я хочу обновить manuf table qtyleft row.

<?php require_once('../Connections/bidco.php'); ?> 

<?php 
mysql_select_db($database_bidco, $bidco); 
$query_rsSaletype = "SELECT * FROM saletype ORDER BY type ASC"; 
$rsSaletype = mysql_query($query_rsSaletype, $bidco) or die(mysql_error()); 
$row_rsSaletype = mysql_fetch_assoc($rsSaletype); 
$totalRows_rsSaletype = mysql_num_rows($rsSaletype); 

mysql_select_db($database_bidco, $bidco); 
$query_rsCustomercategory = "SELECT * FROM buyertype ORDER BY type ASC"; 
$rsCustomercategory = mysql_query($query_rsCustomercategory, $bidco) or die(mysql_error()); 
$row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory); 
$totalRows_rsCustomercategory = mysql_num_rows($rsCustomercategory); 

mysql_select_db('invmgt', mysql_connect('localhost','root','dream2014')) or die(mysql_error()); 
?> 
<?php 
    //Start session 
    session_start();  
    //Unset the variables stored in session 
    unset($_SESSION['SESS_ID']); 
    unset($_SESSION['SESS_Username']); 
    unset($_SESSION['SESS_Name']); 
?> 
<?php 
if (isset ($_POST ['Submit'])) 
{ 
$da=date("Y-m-d"); 
$itemname=$_POST['itemname']; 
$itemcode=$_POST['itemcode']; 
$itemtype=$_POST['itemtype']; 
$price=$_POST['unitprice']; 
$quantity=$_POST['quantity']; 
$ttype=$_POST['select2']; 
$ccat=$_POST['select']; 
$idate=date("Y-m-d"); 

mysql_query("INSERT INTO sold_goods (itemname, itemcode, itemtype, unitprice, quantity, transactiontype, customercategory, Date) VALUES ('$itemname', '$itemcode', '$itemtype', '$unitprice', '$quantity', '$ttype', '$ccat', '$idate')"); 

header("location:sold.php"); 
}      

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
</head> 

<body> 
<table width="711" height="27" border="0"> 
    <tr> 
    <td width="216"><a href="../manufactured_goods/manuf.php">Manufactured Goods</a> </td> 
    <td width="152"><a href="sold.php">Sold Goods</a> </td> 
    <td width="148"><a href="../client_details/client.php">Client Details </a></td> 
    <td width="167"><a href="../users_accounts/users.php">User Accounts </a></td> 
    <td width="167"><a href="../login/menu.php">Home </a></td> 
    <td width="167"><div align="right"><a href="../login/logout.php">Logout </a></div></td> 
    </tr> 
</table> 
<p>&nbsp;</p> 
<form id="form9" name="form9" method="POST" action=""> 
    <table width="828" height="572" border="1" align="center"> 
    <tr> 
     <td height="55" colspan="3"><div align="center"><strong>SOLD GOODS </strong></div></td> 
    </tr> 
    <tr> 
     <td height="33" colspan="2">User</td> 
     <td height="33"><?php date_default_timezone_set('Africa/Nairobi'); echo "Time " . date("h:i:sa"); 
?></td> 
    </tr> 
    <tr> 
     <td height="14">Customer code 
     <div align="center"></div></td> 
     <td height="14">Customer category   
     <select name="select2"> 
      <?php 
do { 
?> 
      <option value="<?php echo $row_rsCustomercategory['type']?>"><?php echo $row_rsCustomercategory['type']?></option> 
      <?php 
} while ($row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory)); 
    $rows = mysql_num_rows($rsCustomercategory); 
    if($rows > 0) { 
     mysql_data_seek($rsCustomercategory, 0); 
     $row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory); 
    } 
?> 
     </select></td> 
     <td height="14"><?php echo "Date of Transaction " . date("Y/m/d")?></td> 
    </tr> 
    <tr> 
     <td height="15">&nbsp;</td> 
     <td height="15">&nbsp;</td> 
     <td height="15">&nbsp;</td> 
    </tr> 
    <tr> 
     <td height="32" colspan="2"><div align="center"><strong>ITEM DETAILS </strong></div></td> 
     <td width="258" rowspan="3"><div align="center"></div> 
      <div align="center"></div></td> 
    </tr> 
    <tr> 
     <td width="227" height="23"><div align="right">Item name </div></td> 
     <td width="321"><input name="itemname" type="text" id=itemname /></td> 
    </tr> 
    <tr> 
     <td><div align="right">Item code </div></td> 
     <td><input name="itemcode" type="text" id="itemcode" /></td> 
    </tr> 
    <tr> 
     <td><div align="right">Item type </div></td> 
     <td><input name="itemtype" type="text" id="itemtype" /></td> 
     <td rowspan="3"><div align="center"></div></td> 
    </tr> 
    <tr> 
     <td height="23"><div align="right">Unit price </div></td> 
     <td><input name="unitprice" type="text" id=price /></td> 
    </tr> 
    <tr> 
     <td height="32"><div align="right">Quantity </div></td> 
     <td><input name="quantity" type="text" id=qty /></td> 
    </tr> 
    <tr> 
     <td height="42" colspan="2"><div align="center"><strong>SALES</strong></div></td> 
     <td><div align="center"></div> 
      <div align="center"></div></td> 
    </tr> 
    <tr> 
     <td><div align="right">Gross</div></td> 
     <td>&nbsp;</td> 
     <td><div align="center"></div></td> 
    </tr> 
    <tr> 
     <td><div align="right">Type of sale </div></td> 
     <td><select name="select"> 
     <?php 
do { 
?> 
     <option value="<?php echo $row_rsSaletype['type']?>"><?php echo $row_rsSaletype['type']?></option> 
     <?php 
} while ($row_rsSaletype = mysql_fetch_assoc($rsSaletype)); 
    $rows = mysql_num_rows($rsSaletype); 
    if($rows > 0) { 
     mysql_data_seek($rsSaletype, 0); 
     $row_rsSaletype = mysql_fetch_assoc($rsSaletype); 
    } 
?> 
     </select></td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td height="28" colspan="2"><div align="center"><strong>DEDUCTIONS</strong></div></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td height="36"><div align="right">Discount</div></td> 
     <td height="36">&nbsp;</td> 
     <td><div align="center"> 
     <input type="submit" name="Submit" value="ADD NEW" /> 
     </div></td> 
    </tr> 
    <tr> 
     <td height="36"><div align="right">V.A.T</div></td> 
     <td height="36">&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td height="36"><div align="right">Net</div></td> 
     <td height="36">&nbsp;</td> 
     <td rowspan="2"><div align="center"> 
      <input type="reset" name="Submit5" value="CANCEL" /> 
     </div></td> 
    </tr> 
    <tr> 
     <td height="30" colspan="2"><div align="center"> 
     <label><strong>CALCULATE</strong></label> 
     </div></td> 
    </tr> 
    </table> 

</form> 

<p>&nbsp;</p> 
<p>&nbsp;</p> 
</body> 
</html> 
<?php 
mysql_free_result($rsSaletype); 

mysql_free_result($rsCustomercategory); 
?> 

Это manuf.php для добавления новых акций

<?php require_once('../Connections/bidco.php'); ?> 
<?php 
if (isset ($_POST ['Submit'])) 
{ 
$da=date("Y-m-d"); 
$itemname=$_POST['itemname']; 
$itemcode=$_POST['itemcode']; 
$itemtype=$_POST['itemtype']; 
$unitprice=$_POST['unitprice']; 
$quantity=$_POST['quantity']; 
$idate=date("Y-m-d"); 

mysql_query("INSERT INTO manuf (itemname, itemcode, itemtype, price, qtyleft, Date) VALUES ('$itemname', '$itemcode', '$itemtype', '$unitprice', '$quantity', '$idate')"); 

header("location:manuf.php"); 
}      

?> 

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
</head> 

<body> 
<p>&nbsp;</p> 
<table width="711" height="27" border="0" align="center"> 
    <tr> 
    <td width="216"><a href="inventory.php">Inventory</a></td> 
    <td width="152"><a href="../sold_goods/sold.php">Sold Goods</a> </td> 
    <td width="148"><a href="../client_details/client.php">Client Details </a></td> 
    <td width="167"><a href="../users_accounts/users.php">User Accounts</a> </td> 
    <td width="167"><a href="../login/menu.php">Home</a> </td> 
    </tr> 
</table> 
<p>&nbsp;</p> 
<form id="form1" name="form1" method="POST" action=""> 
    <table width="743" height="282" border="1" align="center"> 
    <tr> 
     <td colspan="3"><div align="center"><strong>ADD NEW PRODUCT </strong></div></td> 
    </tr> 
    <tr> 
     <td colspan="2">Username </td> 
     <td width="265"><?php date_default_timezone_set('Africa/Nairobi'); echo "Time " . date("h:i:sa"); 
?></td> 
    </tr> 
    <tr> 
     <td width="180"><div align="right">Item name </div></td> 
     <td width="276"><input name="itemname" type="text" id="itemname" /></td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td><div align="right">Item code </div></td> 
     <td><input name="itemcode" type="text" id="itemcode" /></td> 
     <td><div align="center"></div></td> 
    </tr> 
    <tr> 
     <td><div align="right">Type</div></td> 
     <td><input name="itemtype" type="text" id="itemtype" /></td> 
     <td><div align="center"></div></td> 
    </tr> 
    <tr> 
     <td><div align="right">Unit price </div></td> 
     <td><input name="unitprice" type="text" id="unitprice" /></td> 
     <td><div align="center"></div></td> 
    </tr> 
    <tr> 
     <td><div align="right">Quantity</div></td> 
     <td><input name="quantity" type="text" id="quantity" /></td> 
     <td><div align="center"> 
      <input type="submit" name="Submit" value="Add stock" /> 
     </div></td> 
    </tr> 
    <tr> 
     <td><div align="right">Date</div></td> 
     <td><input name="idate" type="varchar" id="idate" /></td> 
     <td><div align="center"> 
      <input type="reset" name="Submit5" value="Cancel" /> 
     </div></td> 
    </tr> 
    </table> 
    <input type="hidden" name="MM_insert" value="form1"> 
</form> 
<div align="center"></div> 
<div align="center"></div> 
<p>&nbsp;</p> 
</body> 
</html> 
+1

Вы [не должны использовать mysql_ * функции в новом коде] (http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). Они больше не поддерживаются и [официально устарели] (https://wiki.php.net/rfc/mysql_deprecation). Узнайте о [подготовленных заявлениях] (http://en.wikipedia.org/wiki/Prepared_statement) и используйте PDO или MySQLi. –

+0

Я не знаком с MySQLi, поэтому я выбрал этот – NoviceProgrammer

ответ

1

После вставки в sold таблицу, обновить manf таблицу, а также:

mysql_query("INSERT INTO sold_goods 
       (itemname, itemcode, itemtype, unitprice, quantity, 
       transactiontype, customercategory, Date) 
       VALUES 
       ('$itemname', '$itemcode', '$itemtype', '$unitprice', 
       '$quantity', '$ttype', '$ccat', '$idate')"); 



mysql_query("UPDATE manuf SET qtyleft = qtyleft - $quantity where 
itemcode = '$itemcode'"); 
+0

Спасибо, он работает. – NoviceProgrammer

Смежные вопросы