Files
k3s-configs/php-test/submit.php
K3s Admin a725f0f933 Add k3s cluster expansion documentation and scripts
- Complete expansion guide for 2/4/6 node scenarios
- Quick join scripts for worker and master nodes
- Health check and diagnostic scripts
- Quick reference card for common operations
2026-01-21 09:02:47 +00:00

51 lines
1.3 KiB
PHP

<?php
require_once 'Database.php';
header('Content-Type: application/json; charset=utf-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: index.php');
exit;
}
try {
// 获取表单数据
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$message = trim($_POST['message'] ?? '');
// 验证必填字段
if (empty($name) || empty($email)) {
throw new Exception('姓名和邮箱为必填项');
}
// 验证邮箱格式
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new Exception('邮箱格式不正确');
}
// 获取数据库连接
$db = Database::getConnection();
// 准备SQL语句
$sql = "INSERT INTO test_data (name, email, message) VALUES (:name, :email, :message)";
$stmt = $db->prepare($sql);
// 绑定参数并执行
$stmt->execute([
':name' => $name,
':email' => $email,
':message' => $message
]);
// 重定向到首页并显示成功消息
header('Location: index.php?status=success');
exit;
} catch (Exception $e) {
// 重定向到首页并显示错误消息
$errorMsg = urlencode($e->getMessage());
header('Location: index.php?status=error&msg=' . $errorMsg);
exit;
}