gpt4 book ai didi

php - 使用 session 传输表值

转载 作者:行者123 更新时间:2023-11-28 23:45:00 25 4
gpt4 key购买 nike

我正在尝试建立一个汽车租赁网站,我已经设法在表格中显示车辆,但现在我想为每辆车添加一个预订按钮,并在不同的页面上显示预订表格。我正在尝试使用这可能吗?

显示页面

<?php session_start(); ?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/basicstyle.css">
</head>

<body>
<?php
include("header.php");
$disp = "select * from selfdrive where City = '" . strtoupper($_SESSION['city']) . "' and Availability = 'YES' ";
$result = mysqli_query($conn, $disp);
echo $num = mysql_num_rows($result);

?>

<table id= "vehicle-display" width="1088" height="49" border="0">
<tr>
<th width="250" scope="col">&nbsp;</th>
<th width="250" scope="col">Model</th>
<th width="200" scope="col">Class</th>
<th width="200" scope="col">Deposit</th>
<th width="200" scope="col">Daily Rate</th>
</tr>
<?php

$i=1;
$num = mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result))
{

//$Image=mysql_result($result,$i,"Image");
//$Model=mysql_result($result,$i,"Model");
//$Class=mysql_result($result,$i,"Class");
//$Deposit=mysql_result($result,$i,"Deposit");
//$Rate=mysql_result($result,$i,"Rate");
//echo "$Image $Model $Class $Deposit $Rate";
//$i++;
?>
<form action="self-booking.php" method="get">
<tr>
<th width="250" scope="col"><img src="<?php echo $row['Image']?>" width="200"></th>
<th width="250" scope="col"><?php echo $row['Model']?></th>
<th width="200" scope="col"><?php echo $row['Class']?></th>
<th width="200" scope="col"><?php echo $row['Deposit']?></th>
<th width="200" scope="col"><?php echo $row['Rate']?></th>
<th width="200" scope="col"><input type="submit" value="Book Now!" name="submit">
<?php for($i=0;$i < $num;$i++){$_SESSION['row']['$i'] = $row['$i'];}?></th>
</tr>
</form>
<?php
}
?>
</table>
</body>
</html>

预订表格页面

 <?php
session_start();
include("session.php");
include("header.php");
?>



<html>
<head>
<title>Booking</title>
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/basicstyle.css">
</head>

<body class="templatemo-bg-gray">
<?php
if(!isset($_SESSION['login_user']))
header("Location: login.php");
else{
?>
<h1 class="margin-bottom-15">Login</h1>

<?php $row = $_SESSION['row']['$i']; ?>
<div id="imageframe">
<img src="<?php echo $row['Image']?>" width="600">
</div>
<div id="vehicle-details">
<?php echo "Model: ".$row['Model']."<br><br>";
echo "Class: ".$row['Class']."<br><br>";
echo "Deposit: Rs.".$row['Deposit']."<br><br>";
echo "Daily Rate: Rs.".$row['Rate']."<br><br>";
?>
</div>



<?php } ?>
<?php include("footer.php"); ?>
</body>
</html>

最佳答案

好的,我想通了。显然不需要 session 。我可以将值传递给 url 中的变量,然后使用 get/post 在下一页中读取它。

  <tr>
<th width="250" scope="col"><img src="<?php echo $row['Image']?>" width="200"></th>
<th width="250" scope="col"><?php echo $row['Model']?></th>
<th width="200" scope="col"><?php echo $row['Class']?></th>
<th width="200" scope="col"><?php echo $row['Deposit']?></th>
<th width="200" scope="col"><?php echo $row['Rate']?></th>
<th width="200" scope="col"><?php echo "<a href=self-booking.php?vid=".$row['VehicleID'].">Book Now!</a>";?> </th>

和阅读...

<?php $vid = $_GET['vid']; 
//echo"<pre>";
//print_r($row);
//echo"</pre>";
$sql = "select * from selfdrive where VehicleID = '".$vid."';";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($result);
$model = $row['Model'];
$class = $row['Class'];
$deposit = $row['Deposit'];
$rate = $row['Rate'];

$sql2 = "select * from customers where Username = '".$_SESSION['login_user']."';";
$res = mysqli_query($conn,$sql2);
$row2 = mysqli_fetch_assoc($res);
?>

关于php - 使用 session 传输表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33747852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com