【问题标题】:Storing radio button data in a session [closed]在会话中存储单选按钮数据[关闭]
【发布时间】:2014-09-18 02:53:36
【问题描述】:

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

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

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

我认为我放在底部的内容是错误的。哈哈。不知道怎么弄,谢谢关注!

【问题讨论】:

  • 您的后期处理在哪里完成? if (isset($_POST['order'])){ $_SESSION['carrier'] = $carrier; $_SESSION['payment'] = $payment;只会在帖子执行时运行,这意味着除非您通过帖子进入此页面,否则它不会运行。在后期处理页面上,这对你没有好处。
  • 嗯 最初我制作了一个页面,将其存储在数据库中。但由于我试图添加一个新页面,我不需要它立即存储在数据库中,而是首先存储在会话中,以便用户可以在将其存储到数据库之前进行确认,然后在同一页面中完成后处理但我删除了在同一页面中输入它的代码。 @jjonesdesign
  • 再次查看后,我相信“订单”可能未设置为在提交时发布。您通过引用询问按钮的名称,我相信您的帖子信息中不包含该名称。而是在您的 FORM 中添加一个名称并使用它。
  • 我照你说的做了,并在表格中添加了一个名称,并将 $carrier 更改为 $_POST['carrier'] 和另一个。但什么也没发生@jjonesdesign
  • 哦,呵呵!我看错了。您正在设置会话“$_SESSION['carrier'] = $carrier;”来自在页面加载时未设置的局部变量。试试 $_SESSION['carrier'] = $_POST['carrier'];

标签: javascript php html


【解决方案1】:

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

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

你可以打电话给他们:

$somthing = $_SESSION['carrier']; 

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

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

【讨论】:

    猜你喜欢
    • 2018-06-08
    • 2011-06-18
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2017-11-19
    • 2011-12-03
    • 2016-09-09
    相关资源
    最近更新 更多