如何写一个用户注册美食网站案例前台有用户注册登录和用户游览模块后台有用户管理模块和留言管理模块怎么用代码完成以上要求
以下是一个简单的用户注册美食网站案例,包括前台和后台两个部分。前台包括用户注册登录和用户浏览模块,后台包括用户管理模块和留言管理模块。
前台部分:
- 用户注册页面
<!DOCTYPE html>
<html>
<head>
<title>用户注册</title>
</head>
<body>
<h1>用户注册</h1>
<form action="register.php" method="post">
<label for="username">用户名:</label>
<input type="text" name="username" id="username" required><br>
<label for="password">密码:</label>
<input type="password" name="password" id="password" required><br>
<label for="email">邮箱:</label>
<input type="email" name="email" id="email" required><br>
<input type="submit" value="注册">
</form>
</body>
</html>
- 用户登录页面
<!DOCTYPE html>
<html>
<head>
<title>用户登录</title>
</head>
<body>
<h1>用户登录</h1>
<form action="login.php" method="post">
<label for="username">用户名:</label>
<input type="text" name="username" id="username" required><br>
<label for="password">密码:</label>
<input type="password" name="password" id="password" required><br>
<input type="submit" value="登录">
</form>
</body>
</html>
- 用户浏览页面
<!DOCTYPE html>
<html>
<head>
<title>美食网站</title>
</head>
<body>
<h1>美食网站</h1>
<p>欢迎来到美食网站!</p>
<p>这里有各种美食的介绍和制作方法,快来看看吧!</p>
</body>
</html>
后台部分:
- 用户管理页面
<!DOCTYPE html>
<html>
<head>
<title>用户管理</title>
</head>
<body>
<h1>用户管理</h1>
<table>
<tr>
<th>用户名</th>
<th>邮箱</th>
<th>操作</th>
</tr>
<?php
// 连接数据库
$con = mysqli_connect("localhost", "root", "", "food_website");
// 查询用户信息
$result = mysqli_query($con, "SELECT * FROM users");
// 输出用户信息
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row['username']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td><a href='delete_user.php?id=".$row['id']."'>删除</a></td>";
echo "</tr>";
}
// 关闭数据库连接
mysqli_close($con);
?>
</table>
</body>
</html>
- 留言管理页面
<!DOCTYPE html>
<html>
<head>
<title>留言管理</title>
</head>
<body>
<h1>留言管理</h1>
<table>
<tr>
<th>姓名</th>
<th>邮箱</th>
<th>留言内容</th>
<th>操作</th>
</tr>
<?php
// 连接数据库
$con = mysqli_connect("localhost", "root", "", "food_website");
// 查询留言信息
$result = mysqli_query($con, "SELECT * FROM messages");
// 输出留言信息
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['content']."</td>";
echo "<td><a href='delete_message.php?id=".$row['id']."'>删除</a></td>";
echo "</tr>";
}
// 关闭数据库连接
mysqli_close($con);
?>
</table>
</body>
</html>
- 注册、登录、用户管理和留言管理的 PHP 代码
register.php:
<?php
// 连接数据库
$con = mysqli_connect("localhost", "root", "", "food_website");
// 获取表单数据
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
// 插入用户数据
$result = mysqli_query($con, "INSERT INTO users (username, password, email) VALUES ('$username', '$password', '$email')");
// 关闭数据库连接
mysqli_close($con);
// 跳转到登录页面
header("location: login.php");
?>
login.php:
<?php
session_start();
// 连接数据库
$con = mysqli_connect("localhost", "root", "", "food_website");
// 获取表单数据
$username = $_POST['username'];
$password = $_POST['password'];
// 查询用户数据
$result = mysqli_query($con, "SELECT * FROM users WHERE username='$username' AND password='$password'");
// 验证用户信息
if (mysqli_num_rows($result) > 0) {
// 设置 session
$_SESSION['username'] = $username;
// 关闭数据库连接
mysqli_close($con);
// 跳转到用户浏览页面
header("location: index.php");
} else {
// 关闭数据库连接
mysqli_close($con);
// 跳转到登录页面
header("location: login.php");
}
?>
delete_user.php:
<?php
// 连接数据库
$con = mysqli_connect("localhost", "root", "", "food_website");
// 获取表单数据
$id = $_GET['id'];
// 删除用户数据
$result = mysqli_query($con, "DELETE FROM users WHERE id=$id");
// 关闭数据库连接
mysqli_close($con);
// 跳转到用户管理页面
header("location: user_management.php");
?>
delete_message.php:
<?php
// 连接数据库
$con = mysqli_connect("localhost", "root", "", "food_website");
// 获取表单数据
$id = $_GET['id'];
// 删除留言数据
$result = mysqli_query($con, "DELETE FROM messages WHERE id=$id");
// 关闭数据库连接
mysqli_close($con);
// 跳转到留言管理页面
header("location: message_management.php");
?>
以上是一个简单的用户注册美食网站案例,仅供参考。实际开发中还需要考虑更多的安全性和用户体验问题
原文地址: https://www.cveoy.top/t/topic/hwv0 著作权归作者所有。请勿转载和采集!