将所选无线电的值传递到下一页

时间:2011-10-24 11:06:08

标签: php mysql post radio

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

我知道这很容易,但我无法解决问题。

我的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)然后尝试回显select deliveryid但无法正常工作。代码是:

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

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

如何从第一页到第二页获取所选的电台选项? 非常感谢, 莱恩

3 个答案:

答案 0 :(得分:2)

尝试在HTML和PHP中的变量名称声明周围加上引号:

HTML:

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

PHP:

echo $_POST["check"];

答案 1 :(得分:1)

代码看起来很好。请参阅以下代码以获取参考。尝试一个test.php

<?php
    if($_POST)
        echo $_POST['check'];

?>
<form name="frm" method="post">
<input type="radio" name="check" id="check" value="1"> 1 
<input type="radio" name="check" id="check" value="2"> 2
<input type="radio" name="check" id="check" value="3"> 3
<input type="submit" name="Submit" />
</form>

用$ _POST ['check']

替换$ _POST [check]

感谢。

答案 2 :(得分:1)

如果您可以使用表格中有多个单选按钮:

<input type="radio" name="check[]" value="<?php echo $rows['deliveryid']; ?>"></td>

然后,在您的结果页面上:

echo implode(", ", $_POST['check']); //To see the list of checks selected