使用会话传输表值

时间:2015-11-17 01:53:24

标签: 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>

1 个答案:

答案 0 :(得分:1)

好的,所以我想通了。显然没有必要参加会议。我可以将值传递给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);
?>