php - 将所选 radio 的值传递到下一页

标签 php mysql forms radio-button

我有一个用单选按钮显示 MySQL 查询结果的 PHP 页面。这是在一个表格里面。我想将所选单选按钮的值传递到下一页。

我知道这很简单,但我无法找到正确的解决方案。

我的PHP页面代码如下:

    <html>
    <head>
    </head>
    <body>
    <?PHP

$tenders="SELECT deliverydetails.deliveryid AS `deliveryid` , deliverydetails.collectionarea1 AS `dispatch` , deliverydetails.trailertype AS `trailer` , deliverydetails.collectiondate AS `collectiondate` , deliverydetails.collectiontime AS `collectiontime` , deliverydetails.destination1 AS `destination` , deliverydetails.arrivaldate AS `arrivaldate` , deliverydetails.arrivaltime AS `arrivaltime` , deliverydetails.route AS `route` , deliverydetails.deliverystatus AS `status` , deliverydetails.comments AS `comments` , deliverydetails.loadid1 AS `load` , loadsummaryview.`order number`AS `load1` , loadsummaryview.`number of cases` AS `cases` , loadsummaryview.`total weight`AS `weight` , loadsummaryview.`transport type`AS `transporttype` , deliverydetails.backhaul AS `backhaul` , deliveryhaulier.haulier AS `haulier`, costbyroute.cost as `cost` FROM deliverydetails, deliveryhaulier, loadsummaryview,costbyroute WHERE deliverydetails.loadid1 = loadsummaryview.`order number` AND deliveryhaulier.deliveryid = deliverydetails.deliveryid AND deliverydetails.deliverystatus ='tenderoffered' and costbyroute.id=deliverydetails.hauliercostbyrouteid and deliveryhaulier.haulier='$haulier' order by deliverydetails.deliveryid";
    $tenderresult=mysql_query($tenders);
    $count=mysql_num_rows($tenderresult);


    ?>

                <form name="form1" method="post" action="viewtenderdetails.php">
                    <table border=1>
                        <tr>

                    <th>&nbsp;</th>
                    <th>Delivery Number</th>    
                    <th>Route</th>          
                    <th>Required Trailer</th>
                    <th>Number of Cases</th>                                      <th>Weight of Load</th>
            <th>Rate</th>                       
            <th>Collection Point</th>
            <th>Destination</th> 
            <th>Colleciton Date</th> 
            <th>CollectionTime</th> 
            <th>DeliveryDate</th> 
            <th>DeliveryTime</th>                       
            <th>Backhaul</th>
            <th>status</th>
            <th>comments</th>
            </tr>

    <?php
        while($rows=mysql_fetch_array($tenderresult)){
    ?>
                    <tr>
                    <td>
    <input type="radio" name=check id=check value="<?php echo $rows['deliveryid']; ?>"></td>


        <td><?php echo $rows['deliveryid']; ?></td>
                    <td><?php echo $rows['route']; ?></td>
                    <td><?php echo $rows['trailer']; ?></td>
            <td><?php echo $rows['cases']; ?></td>
                    <td><?php echo $rows['weight']; ?></td>
            <td><?php echo $rows['cost']; ?></td>
            <td><?php echo $rows['dispatch']; ?></td>
            <td><?php echo $rows['destination']; ?></td>
            <td><?php echo $rows['collectiondate']; ?></td>
            <td><?php echo $rows['collectiontime']; ?></td>
            <td><?php echo $rows['arrivaldate']; ?></td>
            <td><?php echo $rows['arrivaltime']; ?></td>
            <td><?php echo $rows['backhaul']; ?></td>   
            <td><?php echo $rows['status']; ?></td> 
            <td><?php echo $rows['comments']; ?></td>                       </tr>  

    <?php
      }
    ?>
            <tr>
                    <td colspan=3>
    <input name="ViewDetails" type="submit" id="ViewDetails" value="ViewDetails"></td>
                    </tr> 
    </table>

    </form>
    </body>
    </html>

我的下一页 (viewtenderdetails.php) 然后尝试回应选择的 deliveryid 但无法正常工作。代码是:

<html><head><title>Hulamin LOC
</title>
</head>
<body>

          <?PHP
                echo $_POST[check];
    ?>
</body>
</html>

如何将第一页中选中的单选选项放到第二页? 非常感谢, 瑞安

最佳答案

尝试在 HTML 和 PHP 中将变量名声明用引号引起来:

HTML:

<input type="radio" name="check" id="check" value="whatever" />

PHP:

echo $_POST["check"];

关于php - 将所选 radio 的值传递到下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7874651/

相关文章:

php - 如何按两列对MySQL进行排序?

javascript - 单击提交按钮时,临时更改 PHP 中同一页面上的 HTML 结构?

mysql - MySQL 中的表内表?

mysql - 使用 mysql 数据库在 asp.net 中注册数据失败

php - | 之间有什么区别?和||运营商?

php - 生成 11,000,000 个唯一 ID 的最快方法

mysql - 对多列的数据库值进行平均,绕过零/空值

javascript - AJAX 仅发布第一个表单

javascript - Bootstrap 登录下拉菜单 "click"不工作

PHP MySQL 多个 id 插入并设置名称