我已经为我的预订系统创建了一个网站,并使用php将其连接到我的数据库。一切正常,只是当用户选择一个时间时,时间在我的数据库中显示不同。例如,如果我在14:30:00预订了一个时间,它在我的表中显示为00:00:14。我似乎找不到为什么这个问题仍然发生,我已经在MYSQL中更改了我的全球时间,我已经调试了我的HTML代码。顺便说一句,我在Ubuntu桌面22.04上使用apache 2作为我的Web服务器。我在MYSQL中查看了我的全球时区,但它是准确的。我调试了我的html文件,找不到任何东西。我试图将我的列的数据类型从“时间”更改为“varchar”,它没有工作。
这是我的html代码---〉
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tidsbokning för Svanens Tandläkarmottagning</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
h1 {
margin: 0;
font-size: 36px;
}
form {
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f2f2f2;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type=text], input[type=email], input[type=date], input[type=time] {
display: block;
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
input[type=submit], input[type=radio] {
background-color: #333;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
margin-right: 10px;
}
input[type=submit]:hover, input[type=radio]:hover {
background-color: #666;
}
</style>
</head>
<body>
</main>
</body>
<header>
<meta charset="utf-8">
<h1>Tidsbokning för Svanens Tandläkarmottagning</h1>
</header>
<main>
<form class="alt" method="POST" action="submit_booking.php">
<label for="patient_name">Your name:</label>
<input type="text" id="patient_name" name="patient_name" required>
<label for="patient_email">Your email:</label>
<input type="email" id="patient_email" name="patient_email" required>
<label for="appointment_date">Appointment date:</label>
<input type="date" id="appointment_date" name="appointment_date" required>
<label for="appointment_time">Appointment time:</label>
<select id="appointment_time" name="appointment_time" type="time" required>
<option value="">-- Select a time --</option>
<option value="09:00:00">09:00:00 </option>
<option value=09:30:00>09:30:00 </option>
<option value="10:00:00">10:00:00 </option>
<option value="10:30:00">10:30:00 </option>
<option value="11:00:00">11:00:00 </option>
<option value="11:30:00">11:30:00 </option>
<option value="12:00:00">12:00:00 </option>
<option value="12:30:00">12:30:00 </option>
<option value="13:00:00">13:00:00 </option>
<option value="13:30:00">13:30:00 </option>
<option value="14:00:00">14:00:00 </option>
<option value="14:30:00">14:30:00 </option>
<option value="15:00:00">15:00:00 </option>
<option value="15:30:00">15:30:00 </option>
<option value="16:00:00">16:00:00 </option>
<option value="16:30:00">16:30:00 </option>
<option value="17:00:00">17:00:00 </option>
</select>
<input type="submit" name="Boka tid" value="submit">
</form>
</main>
</body>
</html>
这是PHP脚本
//Database connection here
$conn = mysqli_connect($host, $username, $password, $dbname);
if (!$conn) {
die("Connection failed:" . mysqli_connect_error());
}
$name = $_POST['patient_name'];
$email= $_POST['patient_email'];
$date = $_POST['appointment_date'];
$time = $_POST['appointment_time'];
// Prepare and execute SQL statement
$stmt = $conn->prepare("INSERT INTO appointments (patient_name, patient_email, appointment_date, appointment_time) VALUES (?, ?, ?, ?)");
$stmt->bind_param("sssi",$name, $email, $date, $time);
$stmt->execute();
// Close connection and redirect to confirmation page
$stmt->close();
$conn->close();
header("Location: confirmation.php");
exit();
?>
1条答案
按热度按时间ih99xse11#
在时间约会时间请检查您是否使用varchar,文本,或时间戳如果您使用varchar或文本,那么它会工作得很好.但如果使用时间戳可能是问题,检查它并更新.