在PHP个人网页中处理用户反馈,可以通过以下几个步骤实现:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户反馈</title>
</head>
<body>
<h1>用户反馈</h1>
<form action="submit_feedback.php" method="post">
<label for="name">姓名:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">邮箱:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="feedback">反馈内容:</label><br>
<textarea id="feedback" name="feedback" rows="4" cols="50" required></textarea><br><br>
<input type="submit" value="提交反馈">
</form>
</body>
</html>
<?php
// 连接到数据库(如果需要的话)
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 获取用户提交的反馈信息
$name = $_POST['name'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];
// 将反馈信息存储到数据库中(如果需要的话)
$sql = "INSERT INTO feedback (name, email, feedback) VALUES ('$name', '$email', '$feedback')";
if ($conn->query($sql) === TRUE) {
echo "反馈提交成功!感谢您的建议。";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// 关闭数据库连接
$conn->close();
?>
注意:在实际应用中,为了保护用户隐私,你需要对用户提交的电子邮件地址进行验证,确保其有效性,并且在将电子邮件地址存储到数据库之前进行适当的清理。此外,为了防止SQL注入攻击,你应该使用预处理语句来执行数据库查询。