简要介绍我正在做的事情:(如果你匆忙只是跳到底部。)
我将酒店预订系统作为我的大学项目。但是由于这段代码我已经差不多2天才取得任何进展。我已经做了很多研究,并且无数次地改变了我的代码,我不知道还应该做些什么来改进下面的代码。
"保留表"
reserve_id int(5) Primary Key
c_id int(5)
c_username varchar(20)
r_id varchar(2)
r_name varchar(50)
checkin date
checkout date
" cust_info"
c_id int(5) Primary Key
c_name varchar(200)
c_username varchar(20)
c_password varchar(10)
c_phone int(11)
c_email varchar(30)
c_address varchar(300)
"住宿"
r_id varchar(2) Primary Key
r_name varchar(50)
r_price int(10)
r_quantity int(2)
这是我的php代码
<?php
include "dbconnect.php";
include "cust_session.php";
if(isset($_POST['submit'])){
$c_username = $_POST['c_username'];
$r_id = $_POST['r_id'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
if(($c_username==null)||($r_id==null)||($checkin==null)||($checkout==null))
{
}
else
{
$try = "SELECT c.c_id, c.c_username, r.c_id, r.c_username, r.r_id, r.r_name, a.r_id, a.r_name
FROM cust_info c JOIN reserve r
ON c.c_username = r.c_username
JOIN accomodation a
ON a.r_id = r.r_id
WHERE r.c_username = '$c_username' and r.r_id = '$r_id'";
$result = mysqli_query($con,$try);
$data = mysqli_fetch_assoc($result);
$c_id = $data['c_id'];
$r_name = $data['r_name'];
$query = "INSERT INTO 'reserve' ( c_id, c_username, r_id, r_name, checkin, checkout)";
$query .= " VALUES ( '$c_id', $c_username, $r_id, '$r_name', $checkin, $checkout )";
$display_query = mysqli_query($con, $query);
}
}
?>
这是我的&#34; dbconnect.php&#34;
<?php
$con = mysqli_connect('localhost' , 'root' , '' , 'pintar');
if($con){
echo "";
}
else{
die("Database connection failed");
}
?>
这是我的&#34; cust_session.php&#34;
<?php
$mysqli = new mysqli("localhost", "root", "", "pintar");
session_start();
$c_username = $_SESSION['c_username'];
$c_password = $_SESSION['c_password'];
$sql_cust = "select * from cust_info where c_username = '$c_username' and c_password = '$c_password'";
$result_cust = $mysqli->query($sql_cust);
$data_cust = mysqli_fetch_assoc($result_cust);
$c_id = $data_cust['c_id'];
$c_name = $data_cust['c_name'];
$c_username = $data_cust['c_username'];
$c_phone = $data_cust['c_phone'];
$c_email = $data_cust['c_email'];
$c_address = $data_cust['c_address'];
$sql_room = "select * from accomodation";
$result_room = $mysqli->query($sql_room);
$data_room = mysqli_fetch_assoc($result_room);
$r_id = $data_room['r_id'];
$r_name = $data_room['r_name'];
$r_price = $data_room['r_price'];
$r_quantity = $data_room['r_quantity'];
$sql_reserve = "select * from reserve";
$result_reserve = $mysqli->query($sql_reserve);
$data_reserve = mysqli_fetch_assoc($result_reserve);
$reserve_id = $data_reserve['reserve_id'];
$c_id = $data_reserve['c_id'];
$c_username = $data_reserve['c_username'];
$r_id = $data_reserve['r_id'];
$r_name = $data_reserve['r_name'];
$checkin = $data_reserve['checkin'];
$checkout = $data_reserve['checkout'];
?>
我的问题是,我无法将预订信息插入我的预订状态&#39;数据库。我在phpmyadmin中检查了我的SQL语句,没有问题。所以我的猜测是问题在于&#39; mysqli&#39;声明。但是,请随意检查整个代码。
谢谢
顺便说一下,为什么声名低于10的人不能张贴照片?