我有一个 MYSQL 数据库,我正在尝试为它开发一个用于股票跟踪数据库的 php 接口。该数据库具有以下表和字段(简化)。货物将从供应商处收到,然后发给工作人员。数据库打算跟踪货物 表格和字段是 tblparts (partID, PartName, Category, Decsription) tblissues (partID, IssueID, DateIssued, Quantity, IssuedTo) tblreceipts (partID, ReceiptID, DateReceived, ReceivedFrom, VoucherNo, Quantity) 我有需要帮助,我是一个自学的 MYSQL 和 PHP 新手,从自学的 MS Access 转移。事实上,这个数据库在 Access 中工作,但现在需要在线,因此我切换到 php 首先我需要一个表格,它将总结收据和问题,并将按 partID 分组。
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<title>View Transactions</title>
<h1>Transactions</h1>
</head>
<body>
<?php
// connect to the database
include('connect.php');
// query db
$PartID = $_GET['PartID'];
// get results from database
$result = mysql_query("SELECT tblparts.PartName, tblparts.PartID, tblreceiving.ReceivingID, tblreceiving.DateReceived, tblreceiving.VoucherNo, SUM(tblreceiving.Quantity), tblreceiving.ReceivedFrom, tblissues.IssueID, SUM(tblissues.Quantity), tblissues.IssueDate, tblissues.IssuedTo
FROM tblparts
LEFT JOIN tblreceiving
ON tblparts.PartID=tblreceiving.PartID
LEFT JOIN tblissues
ON tblparts.PartID=tblissues.PartID
WHERE tblparts.PartID=$PartID
GROUP BY tblparts.PartID
ORDER BY tblreceiving.TransDate")
or die(mysql_error());
echo "<p><b>View All</b> </a></p>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Part Name</th> <th>Amount Received</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['PartName'] . '</td>';
echo '<td>' . $row['SUM(tblreceiving.Receipts)'] . '</td>';
echo '<td>' . $row['SUM(tblissues.QtyIssued)'] . '</td>';
echo "</table>";
?>
<p><a href="home.php">Home</a></p>
</body>
</html>
其次是输入收到货物和发出货物的代码吗?目前我有以下代码应该插入到收据表中但给出错误我不知道我在哪里弄错了用于插入数据的 html 表单
<html>
<body>
<form action="insert_receipts.php" method="post">
Transaction Date: <input type="text" name="DateReceived" />
Voucher Number: <input type="text" name="VoucherNo" />
Received From: <input type="text" name="ReceivedFrom" />
Quantity: <input type="text" name="Quantity" />
Unit: <input type="text" name="Unit" />
<input type="submit" />
</form>
</body>
</html>
insert_receipts.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("stockcontrol", $con);
$sql="INSERT INTO tblreceiving (Transaction Date, Voucher Number, Received From, Quantity)
VALUES
('$_POST[DateReceived]','$_POST[VoucherNo]','$_POST[ReceivedFrom]','$_POST[Quantity]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
如果要求不高,我希望 insert_receipts.php 也有一个运行总数。