php - 使用 session 传输表值

标签 php html mysql session html-table

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

显示页面

<?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/

相关文章:

php - jQuery 自动完成从 mysql 数据库获取提要

php - Codeigniter 从助手返回验证错误

php - 语法错误或访问冲突 : 1064 - PDO refuses to execute multiple queries (including CREATE TEMPORARY TABLE)

javascript - 为什么 "-webkit-app-region"在大多数代码编辑器中不是定义的 CSS 属性?

c# - 如何防止 MySql 中出现重复行?

php - 从 bash 调用 php 函数 - 带参数

html - 仅在特定部分上搜索和替换

PHP mysqli_connect : authentication method unknown to the client [caching_sha2_password]

MySQL忽略查询中的子分区

javascript - 如何连接自定义按钮而不是数据表按钮?