以下是一个简单的PHP仓库管理系统模板:
<?php
// 连接数据库
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "warehouse_management";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 添加商品
if (isset($_POST["add_product"])) {
$product_name = $_POST["product_name"];
$quantity = $_POST["quantity"];
// 插入商品数据到数据库
$sql = "INSERT INTO products (product_name, quantity) VALUES ('$product_name', '$quantity')";
if ($conn->query($sql) === TRUE) {
echo "商品添加成功";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// 更新商品数量
if (isset($_POST["update_quantity"])) {
$product_id = $_POST["product_id"];
$new_quantity = $_POST["new_quantity"];
// 更新商品数量
$sql = "UPDATE products SET quantity='$new_quantity' WHERE id='$product_id'";
if ($conn->query($sql) === TRUE) {
echo "商品数量更新成功";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
// 查询所有商品
$sql = "SELECT * FROM products";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>仓库管理系统</title>
</head>
<body>
<h1>仓库管理系统</h1>
<h2>添加商品</h2>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<label for="product_name">商品名称:</label>
<input type="text" name="product_name" required><br>
<label for="quantity">数量:</label>
<input type="number" name="quantity" required><br>
<input type="submit" name="add_product" value="添加商品">
</form>
<h2>更新商品数量</h2>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<label for="product_id">商品ID:</label>
<input type="number" name="product_id" required><br>
<label for="new_quantity">新数量:</label>
<input type="number" name="new_quantity" required><br>
<input type="submit" name="update_quantity" value="更新数量">
</form>
<h2>商品列表</h2>
<table>
<tr>
<th>ID</th>
<th>商品名称</th>
<th>数量</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["product_name"] . "</td>";
echo "<td>" . $row["quantity"] . "</td>";
echo "</tr>";
}
} else {
echo "暂无商品";
}
?>
</table>
<?php
$conn->close();
?>
</body>
</html>
这个模板包含了以下功能:
请注意,这只是一个简单的模板,你可以根据自己的需求进行修改和扩展。还需要创建一个数据库,并在代码中更新数据库连接信息。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站