jquery mobile酒店预定php代码
时间: 2023-07-03 21:32:11 浏览: 52
以下是一个简单的 jQuery Mobile 酒店预定 PHP 代码示例:
```php
<?php
// 数据库连接代码
// $conn = mysqli_connect($servername, $username, $password, $dbname);
// 检查是否提交了表单
if(isset($_POST['submit'])) {
// 获取表单数据
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
$roomtype = $_POST['roomtype'];
$numguests = $_POST['numguests'];
// 插入数据到数据库
$sql = "INSERT INTO bookings (name, email, phone, checkin, checkout, roomtype, numguests)
VALUES ('$name', '$email', '$phone', '$checkin', '$checkout', '$roomtype', '$numguests')";
if(mysqli_query($conn, $sql)) {
// 数据库操作成功,重定向到成功页面
header('Location: success.php');
exit;
} else {
// 数据库操作失败,显示错误信息
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>酒店预定</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>酒店预定</h1>
</div>
<div data-role="content">
<form method="post" action="">
<div data-role="fieldcontain">
<label for="name">姓名:</label>
<input type="text" name="name" id="name">
</div>
<div data-role="fieldcontain">
<label for="email">邮箱:</label>
<input type="email" name="email" id="email">
</div>
<div data-role="fieldcontain">
<label for="phone">电话:</label>
<input type="tel" name="phone" id="phone">
</div>
<div data-role="fieldcontain">
<label for="checkin">入住日期:</label>
<input type="date" name="checkin" id="checkin">
</div>
<div data-role="fieldcontain">
<label for="checkout">离店日期:</label>
<input type="date" name="checkout" id="checkout">
</div>
<div data-role="fieldcontain">
<label for="roomtype">房间类型:</label>
<select name="roomtype" id="roomtype">
<option value="single">单人间</option>
<option value="double">双人间</option>
<option value="suite">套房</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="numguests">客人数量:</label>
<input type="number" name="numguests" id="numguests">
</div>
<div data-role="controlgroup" data-type="horizontal">
<input type="submit" name="submit" value="预定">
<input type="reset" name="reset" value="重置">
</div>
</form>
</div>
<div data-role="footer">
<h4>版权所有 © 2021</h4>
</div>
</div>
</body>
</html>
```
这个例子中,我们使用了 jQuery Mobile 框架来创建预定表单。表单数据通过 POST 方法提交到同一个页面中,然后通过 PHP 将数据插入到 MySQL 数据库中。如果操作成功,将重定向到一个成功页面。如果操作失败,则显示错误信息。