【问题标题】:Get id of the vehilce for which button was pressed获取按下按钮的车辆的 ID
【发布时间】:2021-12-14 14:34:44
【问题描述】:

我想做某种预订系统。我在“框”中使用按钮(这是指向预订页面的链接)显示数据库中有关汽车的所有数据,每个框用于一辆车。我想获取用户按下汽车所在框中按钮的汽车的 ID。

这是我的代码

 <!-- Fetching data from rows -->
    <?php
        while($rows = $result->fetch_assoc())
    {
    ?>
    <div class="car_box">
        <div class="car_title">
            <p><b><?php echo $rows['Brand'],' ', $rows['Model'];?></b></p>
        </div>

       <div class="car_description">
            <div class="car_details">
                
                <!-- ENGINE CAPACITY -->
                <p>
                    <b>Engine capacity: </b> <?php  echo $rows['Engine_capacity'];  ?> cm3
                </p>
    
               (...)
    
            <!-- BOOKING -->
            <div class="booking">
                <a href="../Bookings.php" class="book_now_button">Book now</a>
            </div>

        </div>

【问题讨论】:

  • 什么阻碍了你?您是否考虑过使用 HTML 表单,以便遍历网站的机器人不会在途中访问立即预订链接和预订汽车?

标签: php sql


【解决方案1】:

您可以尝试在链接中添加参数。

<a href="../Bookings.php?id=<?php echo $rows['id']; ?>" class="book_now_button">Book now</a>

并使用 $_GET['id'] 在您的 Bookings.php 中检索它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 2020-11-16
    相关资源
    最近更新 更多