代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>
<link rel="icon" href="img/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="css/edit_vehicle.css" />
<title>赛博朋克2077未来车辆---编辑页面</title>
<style type="text/css">
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "cyberpunk";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id = $_GET['id'];
$stmtVehicle = $conn->prepare("SELECT * FROM vehicle WHERE id=?");
$stmtVehicle->bind_param("i", $id);
$stmtVehicle->execute();
$resultVehicle = $stmtVehicle->get_result()->fetch_assoc();
$stmtCategories = $conn->prepare("SELECT category_id, category FROM category_id");
$stmtCategories->execute();
$categoriesResult = $stmtCategories->get_result();
$categories = [];
while ($row = $categoriesResult->fetch_assoc()) {
$categories[$row["category_id"]] = htmlspecialchars($row["category"]);
}
$stmtBrands = $conn->prepare("SELECT id, name FROM vehicle_brands");
$stmtBrands->execute();
$brandsResult = $stmtBrands->get_result();
$brands = [];
while ($row = $brandsResult->fetch_assoc()) {
$brands[$row["id"]] = htmlspecialchars($row["name"]);
}
$stmtSeats = $conn->prepare("SELECT id, seats FROM vehicle_seats");
$stmtSeats->execute();
$seatsResult = $stmtSeats->get_result();
$seats = [];
while ($row = $seatsResult->fetch_assoc()) {
$seats[$row["id"]] = htmlspecialchars($row["seats"]);
}
// Display edit form if vehicle exists
if ($resultVehicle) { ?>
<div class="animate__animated animate__fadeIn">
<video src="video/Cyberpunk_2077_1080.mp4" class="bjimg" autoplay loop muted=></video>
<div class="container">
<form method='post' action='update_vehicle.php' enctype="multipart/form-data" >
<h1 class="title1">Cyberpunk2077<sub class="sub1">未来车辆店</sub></h1>
<input type='hidden' name='id' value='<?php echo htmlspecialchars($resultVehicle['id']); ?>' >
<label for='name' class="labe1">车辆名称:</label>
<input type='text' id='name' name='name' value='<?php echo htmlspecialchars($resultVehicle['name']); ?>' required class="border1"><br><br>
<!-- 品牌下拉菜单 -->
<label for='brand' class="labe1">车辆品牌:</label>
<select id="brand" name="brand" required class="border2">
<?php foreach ($brands as $brandId => $brandName): ?>
<option value="<?php echo htmlspecialchars($brandName); ?>">
<?php echo htmlspecialchars($brandName); ?>
</option>
<?php endforeach; ?>
</select><br><br>
<!-- 将车辆类别修改为下拉菜单 -->
<label for='category' class="labe1">车辆类别:</label>
<select id='category_name' name='category_name' required class="border2">
<?php foreach ($categories as $categoryId => $categoryName): ?>
<option value="<?php echo htmlspecialchars($categoryName); ?>" <?php if ($resultVehicle['category'] == $categoryId) echo 'selected'; ?>>
<?php echo htmlspecialchars($categoryName); ?>
</option>
<?php endforeach; ?>
</select><br><br>
<!-- 座位数下拉菜单 -->
<label for='seats' class="labe1">车辆座位:</label>
<select id="seats" name="seats" required class="border2">
<?php foreach ($seats as $seatId => $seatCount): ?>
<option value="<?php echo htmlspecialchars($seatCount); ?>">
<?php echo htmlspecialchars($seatCount); ?>
</option>
<?php endforeach; ?>
</select>
<label for='price' class="labe1">车辆价格:</label>
<input type='number' id='price' name='price' step='0.01' min='0' value='<?php echo htmlspecialchars($resultVehicle['price']); ?>' required class="border3"><br><br>
<!-- 车辆简介输入框 -->
<label for="description" class="labe1">车辆简介:</label>
<textarea id="description" name="description" class="border5" rows="5" cols="38" required placeholder="请输入车辆简介...">
<?php echo htmlspecialchars($resultVehicle['description']); ?>
</textarea>
<br><br>
<!-- 显示当前车辆图片预览 -->
<?php if (!empty($resultVehicle['car_image'])): ?>
<img id="currentVehicleImage" src="<?php echo htmlspecialchars($resultVehicle['car_Image']); ?>" alt="当前车辆图片预览" class="vehicle-preview" style="max-width: 300px; max-height: 300px;" />
<?php endif; ?>
<!-- 新增图片上传和预览部分 -->
<label for="vehicleImageUpload" class="labe1">更换车辆图片:</label>
<input type="file" id="vehicleImageUpload" name="vehicle_image" accept="image/*" class="border4" ><br><br>
<!-- 新增新上传图片预览容器 -->
<div id="newPreviewContainer" style="float: left;margin-left: 500px;margin-top: -510px;border: px solid blue;width: 300px;height: 280px;background-color: rgba(0,0,0,0.4);">
<h1 class="title1">Cyberpunk2077<sub class="sub1">图片预览</sub></h1>
<img id="newPreviewImage" src="#" class="vehicle-preview" style="max-width: 300px; max-height: 300px;" />
</div>
<button type="submit" class="denglu"><p class="p1">修改</p></button>
<button class="zhuce" onclick="redirectToPage()" type="button"><a class="p1" href="vehicles.php">返回</a></button>
</form>
</div>
</div>
<?php } else { ?>
<p>车辆未找到.</p>
<?php } ?>
<?php $conn->close(); ?>
<script>
function redirectToPage() {
window.location.href = "vehicles.php";
}
document.addEventListener('DOMContentLoaded', function() {
const imgInput = document.getElementById('vehicleImageUpload');
const newPreviewContainer = document.getElementById('newPreviewContainer');
const newPreviewImage = document.getElementById('newPreviewImage');
imgInput.addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
newPreviewImage.src = event.target.result;
newPreviewContainer.style.display = 'block';
};
reader.readAsDataURL(file);
}
});
});
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。