在会话中存储单选按钮数据


Storing radio button data in a session

我想在会话中存储数据,以便在下一页中使用它。

这是我使用单选按钮的代码。

<link rel="stylesheet" type="text/css" href="payout.css"/>
<font face='calibri'>
<?php
    session_start();
    $conn = @mysql_connect("localhost","root","");
    $db = @mysql_select_db("");
    include("includes/functions.php");
    mysql_set_charset("UTF8");
    ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Billing Info</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript">

        $(document).ready(function () {
            $("#center input[value='COD']").click(function () {
                if (this.checked) {
                   $("#centerdown input[value='COD']").prop("checked", true);
                } // end if checked
            });
        }); // end doc ready
        $(document).ready(function () {
            $("#center input[value='PickUp']").click(function () {
                if (this.checked) {
                   $("#centerdown input[value='PickUp']").prop("checked", true);
                } // end if checked
            });
        }); // end doc ready
        $(document).ready(function () {
            $("#center input[value='LBC']").click(function () {
                if (this.checked) {
                   $("#centerdown input[value='BPI']").prop("checked", true);
                } // end if checked
            });
        }); // end doc ready

</script>
<style>
#price{
    color:red;
    font-size:20px;
    padding-right: 10px;
    font-family: "Times New Roman", Times, serif;
    float:right;
}
td{
        display:block;
}
</style>
</head>
<body>
    <input type="hidden" name="command" />
    <div align="center">
        <table border="0" cellpadding="2px">
            <tr><td><table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="500px">
        <?php
            if(is_array($_SESSION['cart'])){
                echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td></td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td></tr>';
                $max=count($_SESSION['cart']);
                for($i=0;$i<$max;$i++){
                    $pid=$_SESSION['cart'][$i]['productid'];
                    $q=$_SESSION['cart'][$i]['qty'];
                    $pname=get_product_prod_name($pid);
                    if($q==0) continue;

            ?>
                    <tr bgcolor="#FFFFFF"><td><?php echo $i+1?></td><td><?php echo $pname?></td>
                    <td>₱<?php echo number_format(get_prod_price($pid),2)?></td>
                    <td><input type="text" name="product<?php echo $pid?>" value="<?php echo $q?>" maxlength="2" size="2" disabled/></td>                    
                    <td>₱<?php echo number_format((get_prod_price($pid)*$q),2)?></td>
                    </tr>
            <?php                   
                }
            ?>
                <tr><td></td><td colspan="5" align='right'><b>Order Total: ₱<?php echo get_order_total()?></b></td></tr>
            <?php
            }
            else{
                echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
            }
        ?>
        </table></td>
                </tr>
        </table>
                    <center><h1>Shipping Method</h1></center>
            <form method="post">
            <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
                <tr>
                    <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?>  value="LBC"></td>
                    <td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td>
                    <td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial.<p>
                        <!--<div id='price'> Additional ₱250 </div></td>-->
                </tr>
                <tr>
                    <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?>  value="PickUp"></td>
                    <td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
                    <td><p>Office hours: 10:00 am to 5:00 pm<p>
                        <!--<div id='price'> Free!! </div></td>-->
                </tr>
            </table>
            <br>
            <br>
        <center><h1>Payment Method</h1></center>
        <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='centerdown'>
                <tr>
                    <td><input type="radio" disabled name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?>  value="BPI"></td>
                    <td><img src="../paymentoptions/BPI.jpg"></td>
                    <td><p>Pay by BPI bank deposit (we need confirmation of payment through email.)<p></td>
                </tr>
                <tr>
                    <td><input type="radio" disabled name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?>  value="PickUp"></td>
                    <td><img src="../paymentoptions/Pick-up.jpg"></td>
                    <td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td>
                </tr>
            </table>
            <table>
            <tr><td><input type="button" value="View Shopping Cart" onclick="window.location='shoppingcart.php?'"></td><td><input type="button" name="order" value="Place Order" onclick="window.location='billing.php?'"/> <!--<input type="button" value="Confirm Order" onclick="window.location='quotation.php?'">--></td></tr>
            </table>
        </form>
<?php 
if (isset($_POST['order'])){
    $_SESSION['carrier'] = $carrier;
    $_SESSION['payment'] = $payment;
}
?>
    </div>

</body>
</html>

我认为我放在底部的是错误的。哈哈。我不知道怎么做,谢谢你的帮忙!

这些变量现在应该存储在会话内存中。

这些将在会话启动的任何页面上可用,直到被覆盖或销毁,或者浏览器关闭/超时。

你可以称之为:

$somthing = $_SESSION['carrier']; 

或者你需要如何使用它们。

 <input name='blah' value='<?php echo $_SESSION['carrier'];?>'>