2011-10-24 11 views
1

私はラジオボタンで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をエコーし​​ようとしますが、正常に動作しません。コードは次のとおりです。私は2ページに、最初のページから選択した無線オプションを取得できますか

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

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

? 多くのおかげで、 ライアン

+2

あなたが期待する行動は何ですか?ラジオボタンは次のように動作するはずです:$ _POST ['check']少なくとも1つのオプションが選択されていれば存在します.. $ _POST ['check']ではなく、$ _POST [check]でないことも確認してください – mishu

+0

なぜdonあなたは正しくタグ付けしていますか? –

+1

"> –

答えて

2

あなたのHTMLやPHPの両方で変数名の宣言を囲む引用符を入れてみてください:

HTML:

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

PHP:

echo $_POST["check"]; 
1

コードルックス良い。参照のために以下のコードを参照してください。

感謝[ 'チェック'] $ _POSTと$ _POST [チェック]を置き換え

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

1つのtest.phpをしてみてください。

1

使用できる形式で、複数のラジオボタンがある場合:

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

そして、あなたの結果ページでは:

echo implode(", ", $_POST['check']); //To see the list of checks selected 
関連する問題