将所选单选按钮的值传递到下一页

发布于 2024-12-11 17:23:33 字数 4619 浏览 0 评论 0原文

我有一个 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)尝试回显选择的交付 ID,但无法正常工作。代码是:

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

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

如何将所选的单选选项从第一页转移到第二页? 非常感谢, 瑞安

I have a PHP page that displays the result of a MySQL query with radio buttons. This is inside a form. I want to pass the value of the selected radio button to the next page.

I know this is an easy one but I cant come right with the solution.

My code for the PHP Page is as follows:

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

My next page(viewtenderdetails.php) then tries to echo the select deliveryid but fails to work correctly. the code is:

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

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

How can I get the selected radio option from the first page onto the second page?
Many Thanks,
Ryan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云淡月浅 2024-12-18 17:23:33

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

HTML:

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

PHP:

echo $_POST["check"];

Try putting quotation marks around the variable name declarations in both your HTML and PHP:

HTML:

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

PHP:

echo $_POST["check"];
怪异←思 2024-12-18 17:23:33

代码看起来不错。请参考下面的代码以供参考。尝试在一个 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']

谢谢。

Code Looks fine. Refer below code for referance. try in one 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>

Replace $_POST[check] with $_POST['check']

Thanks.

给不了的爱 2024-12-18 17:23:33

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

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

然后,在结果页面上:

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

if there are more than one radio buttons in the form you can use :

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

And then, on your result page:

echo implode(", ", $_POST['check']); //To see the list of checks selected
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文