核心功能
用户
手机扫码进行信息登记
管理员
1 搜索访客信息(可根据关键字,性别,公司名称,登记时间等搜索)
2 删除访客信息
3 导出所有数据为Excel





数据库设计


部分源码
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
// ====== 数据库连接逻辑 ======
require 'db.php';
$alert = '';
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = isset($_POST['name']) ? $_POST['name'] : '';
$gender = isset($_POST['gender']) ? $_POST['gender'] : '';
$company = isset($_POST['company']) ? $_POST['company'] : '';
$reason = isset($_POST['reason']) ? $_POST['reason'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$sql = "INSERT INTO user (name, gender, company, reason, phone, email) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
if ($stmt->execute([$name, $gender, $company, $reason, $phone, $email])) {
$_SESSION['alert'] = "信息提交成功!";
header("Location: index.php");
exit;
} else {
$_SESSION['alert'] = "提交失败,请重试。";
header("Location: index.php");
exit;
}
}
// 显示并清除 session 中的提示信息
if (isset($_SESSION['alert'])) {
$alert = $_SESSION['alert'];
unset($_SESSION['alert']);
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>访客信息登记系统</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f4f6f8;
margin: 0;
padding: 0;
}
.container {
max-width: 400px;
margin: 50px auto;
background: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: #1E90FF;
}
form input, form select, form button {
display: block;
width: 100%;
margin: 10px 0;
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 6px;
}
form button {
background-color: #1E90FF;
color: #fff;
cursor: pointer;
border: none;
}
form button:hover {
background-color: #187bcd;
}
</style>
</head>
<body>
<div class="container">
<h2>访客信息登记系统</h2>
<form method="POST">
<input type="text" name="name" placeholder="姓名" required />
<select name="gender" required>
<option value="">性别</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
<input type="text" name="company" placeholder="公司" required />
<input type="text" name="reason" placeholder="来访事由" required />
<input type="tel" name="phone" placeholder="电话" required />
<input type="email" name="email" placeholder="电子邮箱" required />
<button type="submit">提交</button>
</form>
</div>
<?php if ($alert): ?>
<script>
alert("<?= htmlspecialchars($alert, ENT_QUOTES) ?>");
</script>
<?php endif; ?>
</body>
</html>