<?php
session_start();
$hostname="localhost"; //local server name default localhost
$username="root"; //mysql username default is root.
$password=""; //blank if no password is set for mysql.
$数据库=“总线票证预约”; //您创建的数据库名称
$con=mysqli_connect($hostname,$username,$password,$database);
if(isset($_SESSION['id']))
{
include("config.php");
$uid = $_SESSION['id'];
$bus = $_GET['bus'];
$seat = $_GET['seat'];
$choice = $_GET['choice'];
$bust = $bus.'bus';
$date = date("Y-m-d");
$query = mysqli_query($con,"Select * from bus where id ='$bus'");
if($query){
$re1 = mysqli_fetch_array($query);
$bus_name = $re1['bus_name'];
$from = $re1['from_stop'];
$to = $re1['to_stop'];
$dept_time = $re1['dept_time'];
$arrival_time = $re1['arrival_time'];
$distance = $re1['distance'];
$fare = $re1['fare'];
}
if($choice !='')
{
if($choice=='W' && $seat==1)
{
$ query2 =“选择*来自$ bust,其中status ='可用'AND state ='$ choice'limit 0,$ seat”;
$p = mysqli_query($con,$query2);
$re = mysqli_num_rows($p);
}
else
{
$query2 = "Select * from $bust where status='Available' limit 0,$seat";
$p = mysqli_query($con,$query2);
$re = mysqli_num_rows($p);
}
if($re>=$seat)
{
while($r = mysqli_fetch_array($p))
{
$id = $r['id'];
$q3 = mysqli_query($con,"update $bust set status ='Booked' where id='$id'");
$q4 = mysqli_query($con,"insert into user_history(user_id, bus_id,bus_name, from_stop ,
to_stop,booking_date,seat_no_booked,dept_time,distance,fare)
values('".$uid."','".$bus."','".$bus_name."', '".$from."', '".$to."', '".$date."', '".$id."',
'“。$ dept_time。”','“。$ distance。”','“。$ fare。”')“);
}
?>
<script>
答案 0 :(得分:0)
首先,学习如何发布问题。其次你用“Python”标记了这个问题,这是php代码。
并非他们中最好的一个。