如何显示单选按钮的数据


How to display the data from radio button?

我有一个问题,我试图做一个收据类型的页面,将显示购买的项目,总价,数量和东西。所有这些都有用。直到我需要添加交付选项和付款选项。

在我可以成功地从单选按钮输入数据到我的数据库之前,但现在我只需要先显示它们,然后才能在数据库中输入它们。

这是我的billing.php页面,用户将选择他/她的交付选项和支付选项。

<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");
    if(isset($_GET['command']) && $_GET['command']=='update'){

        $first_name=$_SESSION['first_name'];
        $email=$_SESSION['email'];
        $home_address=$_SESSION['home_address'];
        $mobile_phone=$_SESSION['mobile_phone'];
        $carrier=$_REQUEST['carrier'];
        $payment=$_REQUEST['payment'];
        $result=mysql_query("insert into customers values('','$first_name','$email','$home_address','$mobile_phone','$carrier','$payment')");
        $customerid=mysql_insert_id();
        date_default_timezone_set("Asia/Hong_Kong");
        $date=date('Y-m-d h:i:s');
        $result=mysql_query("insert into orders values('','$date','$customerid')");
        $orderid=mysql_insert_id();
        $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){
            $pid=$_SESSION['cart'][$i]['productid'];
            $q=$_SESSION['cart'][$i]['qty'];
            $price=get_prod_price($pid);
            mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
        }
        header('refresh: 0; url=homeframe.html'); // to be redirected
        exit(); // para mawala ang puta, tumigil ang script.
    }
//  else if(isset($_REQUEST['success']) && $_REQUEST['success']=='1'){
//  header('refresh: 0; url=samplebrand.php');
//  $message = "Thank you for buying, You will now be redirected";
//  echo("<script type='text/javascript'>alert('$message');</script>");
//  }
    ?>
<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">
    function validate(){
        var f=document.form1;
        f.command.value='update';
        f.submit();
        alert("Order submitted");
    }
$(document).ready(function () {
    $("#center input[name='carrier2']").click(function () {
        if (this.checked) {
           $("#centerdown input[name='payment3']").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>
    <form name="form1" onsubmit="return validate()">
    <input type="hidden" name="command" />
    <div align="center">
        <h1 align="center">Shipping and Payment</h1>
        <table border="0" cellpadding="2px">
            <tr><td>Order Total:</td><td>₱ <?php echo get_order_total()?></td><td>&nbsp;</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="img/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="carrier2" <?php if (isset($carrier) && $carrier=="COD") echo "checked";?>  value="COD"></td>
                    <td><img src="img/Cash on Delivery.jpg" alt="COE" class="picture" height="90" width="125"/></td>
                    <td><p>This service is only available for Meto Manila and Metro Cebu.<p>
                        <div id='price'> Additional ₱180 </div></td>
                </tr>
                <tr>
                    <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="Personal") echo "checked";?>  value="Personal"></td>
                    <td><img src="img/buybranded2.jpg" alt="buybranded" class="picture"/></td>
                    <td><p>The Shipping takes 2-3 days after processing for NCR and 3-5 days for any provincial.<p>
                        <div id='price'> Additional ₱100 </div></td>
                </tr>
                <tr>
                    <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="NextDayDelivery") echo "checked";?>  value="NextDayDelivery"></td>
                    <td><img src="img/NextdayDelivery.jpg" alt="NextDayDelivery" 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 ₱150 </div></td>
                </tr>
                <tr>
                    <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="SameDayDelivery") echo "checked";?>  value="SameDayDelivery"></td>
                    <td><img src="img/Same day Delivery.jpg" alt="SameDayDelivery" class="picture"/></td>
                    <td><p>Available only for NCR. Get your sporting good/s the same day you purchase the item. Cutoff is 12noon.<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="img/Pick-up.jpg" alt="Pick-Up" class="picture"/></td>
                    <td><p>Office hours: 10:00 am to 6: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" name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?>  value="BPI"></td>
                    <td><img src="img/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" name="payment" <?php if (isset($payment) && $payment=="PayPal") echo "checked";?>  value="PayPal"></td>
                    <td><img src="img/paypal.gif"></td>
                    <td><p>Pay with your PayPal account, credit card (CB, Visa, Mastercard...), or private credit card.<p></td>
                </tr>
                -->
                <tr>
                    <td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?>  value="PickUp"></td>
                    <td><img src="img/cashondelivery.gif"></td>
                    <td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td>
                </tr>
                <tr>
                    <td><input type="radio" name="payment3" <?php if (isset($payment) && $payment=="COD") echo "checked";?>  value="COD"></td>
                    <td><img src="img/Cash on Delivery.jpg" height="90" width="125"/></td>
                    <td><p>Pay with your Cash on Delivery (COD)<br>Choose this option if you have selected COD under shipping. Otherwise, choose other options for payment.<p></td>
                </tr>
            </table>
            <table>
            <tr><td><!--<input type="submit" value="Place Order"/> --> <input type="button" value="Confirm Order" onclick="window.location='quotation.php?'"></td></tr>
            </table>
        </form>
    </div>
</form>

</body>
</html>

以前,当我点击提交按钮,它将存储在数据库中,现在我改变了按钮,所以它将链接在这里的quote .php。它成功地显示了所有购买的产品和所有这些东西,除了交付选项

承运人

和支付选项

付款

这是我的引言。php

<link rel="stylesheet" type="text/css" href="payout.css"/>
<font face='calibri'>
<?php
    session_start();
    $conn = @mysql_connect("localhost","root","12148qx3er");
    $db = @mysql_select_db("buybranded");
    include("includes/functions.php");
    mysql_set_charset("UTF8");
    if(isset($_GET['command']) && $_GET['command']=='update'){

        $first_name=$_SESSION['first_name'];
        $email=$_SESSION['email'];
        $home_address=$_SESSION['home_address'];
        $mobile_phone=$_SESSION['mobile_phone'];
        $carrier=$_REQUEST['carrier'];
        $payment=$_REQUEST['payment'];
        $result=mysql_query("insert into customers values('','$first_name','$email','$home_address','$mobile_phone','$carrier','$payment')");
        $customerid=mysql_insert_id();
        date_default_timezone_set("Asia/Hong_Kong");
        $date=date('Y-m-d h:i:s');
        $result=mysql_query("insert into orders values('','$date','$customerid')");
        $orderid=mysql_insert_id();
        $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){
            $pid=$_SESSION['cart'][$i]['productid'];
            $q=$_SESSION['cart'][$i]['qty'];
            $price=get_prod_price($pid);
            mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
        }
        header('refresh: 0; url=homeframe.html'); // to be redirected
        exit(); // para mawala ang puta, tumigil ang script.
    }

//  else if(isset($_REQUEST['success']) && $_REQUEST['success']=='1'){
//  header('refresh: 0; url=samplebrand.php');
//  $message = "Thank you for buying, You will now be redirected";
//  echo("<script type='text/javascript'>alert('$message');</script>");
//  }
    ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Billing Info</title>
<script language="javascript">
    function validate(){
        var f=document.form1;
        f.command.value='update';
        f.submit();
        alert("Order submitted");
    }
</script>
<style>
#price{
    color:red;
    font-size:20px;
    padding-right: 10px;
    font-family: "Times New Roman", Times, serif;
    float:right;
}
</style>
</head>
<body>
    <form name="form1" onsubmit="return validate()">
    <input type="hidden" name="command" />
    <div align="center">
        <h1 align="center">Order Quotation</h1>
        <!--<table border="0" cellpadding="2px">
            <tr><td>Order Total:</td><td>₱ <?php echo get_order_total()?></td><td>&nbsp;</td>
                </tr>
        </table>-->



            <form method="post">
                <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>Serial</td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td><td>Options</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 get_prod_price($pid)?></td>
                    <td><input type="text" name="product<?php echo $pid?>" value="<?php echo $q?>" maxlength="2" size="2" disabled/></td>                    
                    <td>₱<?php echo get_prod_price($pid)*$q?></td>
                    <td><a href="javascript:del(<?php echo $pid?>)">Remove</a></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>";
            }
        ?>
        <?php 
                $carrier=$_SESSION['carrier'];
                $payment=$_SESSION['payment'];
                echo $carrier
                ?>
        </table>


            <table>
            <tr><td><input type="submit" value="Place Order"/></td></tr>
            </table>
        </form>
    </div>
</form>

</body>
</html>

正如你所看到的,我试图在底部回显$载体,但我得到这个身份不明的索引错误,我尝试使用$_SESSION和$_REQUEST。但我似乎不能让它出现。

对不起,如果这是一个很长的问题,我只是有麻烦与我的项目。

删掉这两行:

            $carrier=$_SESSION['carrier'];
            $payment=$_SESSION['payment'];

您已经在之前的$_REQUEST中设置了变量。您从未将它们复制到会话中,因此不需要在这里重新分配变量。