下面是一个简单的示例代码,用于生成库存调整记录功能的PHP代码:
<?php
// 连接数据库
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 处理库存调整记录的表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$product_id = $_POST["product_id"];
$adjustment_type = $_POST["adjustment_type"];
$quantity = $_POST["quantity"];
$reason = $_POST["reason"];
// 插入库存调整记录到数据库
$sql = "INSERT INTO inventory_adjustments (product_id, adjustment_type, quantity, reason) VALUES ('$product_id', '$adjustment_type', '$quantity', '$reason')";
if ($conn->query($sql) === TRUE) {
echo "库存调整记录已添加成功";
} else {
echo "添加库存调整记录时出错: " . $conn->error;
}
}
// 获取所有库存调整记录
$sql = "SELECT * FROM inventory_adjustments";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 输出每条库存调整记录
while($row = $result->fetch_assoc()) {
echo "ID: " . $row["id"]. " - 产品ID: " . $row["product_id"]. " - 调整类型: " . $row["adjustment_type"]. " - 数量: " . $row["quantity"]. " - 原因: " . $row["reason"]. "<br>";
}
} else {
echo "没有库存调整记录";
}
$conn->close();
?>
<!-- 库存调整记录表单 -->
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<label for="product_id">产品ID:</label>
<input type="text" name="product_id" id="product_id" required><br>
<label for="adjustment_type">调整类型:</label>
<select name="adjustment_type" id="adjustment_type" required>
<option value="增加">增加</option>
<option value="减少">减少</option>
</select><br>
<label for="quantity">数量:</label>
<input type="number" name="quantity" id="quantity" required><br>
<label for="reason">原因:</label>
<textarea name="reason" id="reason" required></textarea><br>
<input type="submit" value="提交">
</form>
上述代码实现了以下功能:
请根据你的具体需求和数据库结构进行适当的修改和调整。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站