first commit

This commit is contained in:
2025-01-09 11:57:41 +08:00
commit 700113c47b
47 changed files with 2050 additions and 0 deletions

73
register.php Normal file
View File

@ -0,0 +1,73 @@
<?php
include_once "db_config.php";
$conn = $link;
// 检查连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 检查是否提交表单
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
// 表单验证
if (empty($name) || empty($password)) {
echo "姓名和密码不能为空!";
} else {
// 密码加密
$hashedPassword = md5($password);
// 查询是否存在该用户
$sql = "SELECT * FROM user_70 WHERE name = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $name);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// 用户存在,更新密码
$updateSql = "UPDATE user_70 SET password = ? WHERE name = ?";
$updateStmt = $conn->prepare($updateSql);
$updateStmt->bind_param("ss", $hashedPassword, $name);
if ($updateStmt->execute()) {
echo "密码更新成功!";
} else {
echo "密码更新失败:" . $conn->error;
}
} else {
// 用户不存在,插入新用户
$insertSql = "INSERT INTO user_70 (name, password) VALUES (?, ?)";
$insertStmt = $conn->prepare($insertSql);
$insertStmt->bind_param("ss", $name, $hashedPassword);
if ($insertStmt->execute()) {
echo "注册成功!";
} else {
echo "注册失败:" . $conn->error;
}
}
}
}
// 关闭数据库连接
$conn->close();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>用户注册与修改密码</title>
</head>
<body>
<form method="POST" action="register.php">
<label for="name">姓名:</label>
<input type="text" id="name" name="name"><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password"><br>
<button type="submit" id="ok" name="ok" value="ok">提交</button>
</form>
</body>
</html>