如何从单选按钮显示数据?

时间:2014-08-21 07:01:14

标签: php forms session shopping-cart

我有一个问题,我正在尝试制作收据类型的页面,显示购买的商品,总价格,数量和东西。所有这些工作。直到我需要添加交付选项和付款选项。

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

这是我的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>

之前,当我点击提交按钮时,它会将其存储在数据库中,现在我更改了按钮,因此它将在quotation.php中链接到此处。它成功地显示了所有购买的产品和所有这些东西,除了交付选项

  

载体

和付款选项

  

付款

这是我的quotation.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>

正如你所看到的,我试图在底部回应$ carrier,但是我得到了这个未识别的索引错误,我尝试使用$ _SESSION和$ _REQUEST。但我似乎无法让它出现。

对不起,如果这是一个很长的问题,我只是遇到了我的项目问题。

1 个答案:

答案 0 :(得分:0)

摆脱这两行:

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

您已经在$_REQUEST之前设置了变量。您永远不会将它们复制到会话中,因此无需在此处重新分配变量。