以下是一个简单的客户服务记录管理系统的PHP代码示例:
<?php
// 连接到数据库
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "customer_service";
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接是否成功
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 处理提交的表单数据
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
// 将数据插入到数据库中
$sql = "INSERT INTO customer_records (name, email, message) VALUES ('$name', '$email', '$message')";
if ($conn->query($sql) === TRUE) {
echo "记录添加成功";
} else {
echo "添加记录时发生错误: " . $conn->error;
}
}
// 获取所有的客户记录
$sql = "SELECT * FROM customer_records";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 输出数据到表格中
echo "<table><tr><th>ID</th><th>姓名</th><th>邮箱</th><th>留言</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td><td>".$row["message"]."</td></tr>";
}
echo "</table>";
} else {
echo "暂无客户记录";
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>客户服务记录管理</title>
</head>
<body>
<h1>客户服务记录管理</h1>
<h2>添加新记录</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="name">姓名:</label>
<input type="text" name="name" required><br><br>
<label for="email">邮箱:</label>
<input type="email" name="email" required><br><br>
<label for="message">留言:</label>
<textarea name="message" required></textarea><br><br>
<input type="submit" value="提交">
</form>
<h2>客户记录</h2>
<?php
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>姓名</th><th>邮箱</th><th>留言</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td><td>".$row["message"]."</td></tr>";
}
echo "</table>";
} else {
echo "暂无客户记录";
}
?>
</body>
</html>
请注意,此代码仅为示例,可能需要根据实际需求进行修改和优化。此代码假设已在本地服务器上创建了名为"customer_service"的数据库,并且已创建了名为"customer_records"的表格,表格包含id、name、email和message字段。
上一篇:检测php环境(php测试软件)
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站