代码生成(用html+css+js+php+js+mysql写一个星际争霸2赛事网站的赛事管理员页面)
时间: 2023-09-30 09:02:56 浏览: 87
很高兴为你提供代码生成。以下是一个基本的 HTML/CSS/JS/PHP/MySQL 网站,用于管理星际争霸2赛事。
HTML:
```html
<!DOCTYPE html>
<html>
<head>
<title>星际争霸2赛事管理</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<h1>星际争霸2赛事管理</h1>
<form method="POST" action="add_match.php">
<label>比赛名称:</label>
<input type="text" name="match_name" required>
<label>比赛日期:</label>
<input type="date" name="match_date" required>
<label>比赛时间:</label>
<input type="time" name="match_time" required>
<label>比赛地点:</label>
<input type="text" name="match_location" required>
<label>比赛描述:</label>
<textarea name="match_description" required></textarea>
<input type="submit" name="submit" value="添加比赛">
</form>
<hr>
<table>
<thead>
<tr>
<th>比赛名称</th>
<th>比赛日期</th>
<th>比赛时间</th>
<th>比赛地点</th>
<th>比赛描述</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php
include('config.php');
$sql = "SELECT * FROM matches";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["match_name"] . "</td>";
echo "<td>" . $row["match_date"] . "</td>";
echo "<td>" . $row["match_time"] . "</td>";
echo "<td>" . $row["match_location"] . "</td>";
echo "<td>" . $row["match_description"] . "</td>";
echo "<td><a href='edit_match.php?id=" . $row["id"] . "'>编辑</a> | <a href='delete_match.php?id=" . $row["id"] . "'>删除</a></td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='6'>暂无比赛</td></tr>";
}
?>
</tbody>
</table>
</div>
</body>
</html>
```
CSS:
```css
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
form label {
display: block;
margin-bottom: 10px;
}
form input[type="text"], form input[type="date"], form input[type="time"], form textarea {
width: 100%;
padding: 10px;
margin-bottom: 20px;
}
form input[type="submit"] {
display: block;
margin: 0 auto;
padding: 10px 20px;
background-color: #337ab7;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 50px;
}
thead th, tbody td {
padding: 10px;
border: 1px solid #ddd;
}
thead th {
background-color: #f2f2f2;
text-align: left;
}
tbody td:last-child {
text-align: center;
}
tbody td:last-child a {
color: #ff0000;
text-decoration: none;
margin-left: 10px;
}
```
JS:
```javascript
// 没有Javascript代码
```
PHP:
config.php
```php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
?>
```
add_match.php
```php
<?php
include('config.php');
$match_name = $_POST['match_name'];
$match_date = $_POST['match_date'];
$match_time = $_POST['match_time'];
$match_location = $_POST['match_location'];
$match_description = $_POST['match_description'];
$sql = "INSERT INTO matches (match_name, match_date, match_time, match_location, match_description) VALUES ('$match_name', '$match_date', '$match_time', '$match_location', '$match_description')";
if ($conn->query($sql) === TRUE) {
header('Location: index.php');
} else {
echo "添加比赛失败: " . $conn->error;
}
$conn->close();
?>
```
edit_match.php
```php
<?php
include('config.php');
$id = $_GET['id'];
$sql = "SELECT * FROM matches WHERE id='$id'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>编辑比赛</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<h1>编辑比赛</h1>
<form method="POST" action="update_match.php">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<label>比赛名称:</label>
<input type="text" name="match_name" value="<?php echo $row['match_name']; ?>" required>
<label>比赛日期:</label>
<input type="date" name="match_date" value="<?php echo $row['match_date']; ?>" required>
<label>比赛时间:</label>
<input type="time" name="match_time" value="<?php echo $row['match_time']; ?>" required>
<label>比赛地点:</label>
<input type="text" name="match_location" value="<?php echo $row['match_location']; ?>" required>
<label>比赛描述:</label>
<textarea name="match_description" required><?php echo $row['match_description']; ?></textarea>
<input type="submit" name="submit" value="保存">
</form>
</div>
</body>
</html>
```
update_match.php
```php
<?php
include('config.php');
$id = $_POST['id'];
$match_name = $_POST['match_name'];
$match_date = $_POST['match_date'];
$match_time = $_POST['match_time'];
$match_location = $_POST['match_location'];
$match_description = $_POST['match_description'];
$sql = "UPDATE matches SET match_name='$match_name', match_date='$match_date', match_time='$match_time', match_location='$match_location', match_description='$match_description' WHERE id='$id'";
if ($conn->query($sql) === TRUE) {
header('Location: index.php');
} else {
echo "更新比赛失败: " . $conn->error;
}
$conn->close();
?>
```
delete_match.php
```php
<?php
include('config.php');
$id = $_GET['id'];
$sql = "DELETE FROM matches WHERE id='$id'";
if ($conn->query($sql) === TRUE) {
header('Location: index.php');
} else {
echo "删除比赛失败: " . $conn->error;
}
$conn->close();
?>
```
MySQL:
```mysql
-- 创建数据库
CREATE DATABASE `database_name`;
-- 创建数据表
CREATE TABLE `matches` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`match_name` varchar(255) NOT NULL,
`match_date` date NOT NULL,
`match_time` time NOT NULL,
`match_location` varchar(255) NOT NULL,
`match_description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 添加测试数据
INSERT INTO `matches` (`match_name`, `match_date`, `match_time`, `match_location`, `match_description`) VALUES
('2019全球总决赛', '2019-11-02', '12:00:00', '首尔', '全球最高荣誉的星际争霸2比赛'),
('2019 WCS全球总决赛', '2019-11-03', '13:00:00', '首尔', '全球最高荣誉的星际争霸2比赛');
```
希望这些代码能够帮到你,如有任何问题,请随时问我。
阅读全文