一个开关盒中有两个值

时间:2017-03-08 16:54:10

标签: php html mysql switch-statement case

我是新手所以请耐心等待。 我想要一个单选按钮,当用户选择一个时,会将两个值发送到数据库(记录表)。一种是用户选择的服务类型,另一种是相应的价格。但“服务”和“价格”来自另一个表,这意味着该值取决于“ms_pricelist”数据库的内容。这是我的代码:

(这是我的输入表单。让我们尝试关注<input type="radio">按钮)

                    <form method="post" action="">
                    <table style="width: 10%;">

     <p style="font-size: 30px; font-family: Verdana;"> &nbsp Service Contract </p>
      <hr style="margin-top: -20px; width: 95%;">

    <p style="margin-left: 50px;">Name of Deceased:  <input type="text" name="service_deceased" value="<?php echo $query2['service_deceased']; ?>" />
    <br><br>

    <p style="margin-left: 50px;">Type of Service:  
    <input type="radio" name="service_type">Sunny Star</button>
    <input type="radio" name="service_type">Lemon Tropic</button>
    <input type="radio" name="service_type">White Fairy</button><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <input type="radio" name="service_type">Chinese Holy</button>
    <input type="radio" name="service_type">Red Ginger</button>
    <input type="radio" name="service_type">Blue Days</button></p>
     &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

    <p style="margin-left: 50px;">Amount:   <input type="text" name="service_amount" value="<?php echo $query2['service_amount']; ?>" />
      </p>

    <p style="margin-left: 410px;">  NET AMOUNT:  <input type="text" name="net_amount" value="<?php echo $query2['net_amount']; ?>" />
    <br></p>

        <input type="submit" name="submit" value="Update" style="margin-left: 1000px; height: 50px; width: 150px;" />
    </form>

这是我的'ms_pricelist'数据库

[ms_priceID |    ms_name   | ms_price]
--------------------------------------
[    1      |  Sunny Star  |    28000]
[    2      | Lemon Tropic |    48000]
[    3      |  White Fairy |    58000]
[    4      | Chinese Holy |    98000]
[    5      |  Red Ginger  |   168000]
[    6      |   Blue Days  |   250000]

'service_type'是ms_name应该存储在记录表中的位置,'service_amount'用于ms_price。

有可能吗?我差不多一个月都在寻找答案,但仍然找不到答案。有关如何完成它的任何建议?我正在使用PHP和MYSQL。非常感谢你!

修改

这是表单的php代码。

<?php
include('connect-db.php');
    if(isset($_GET['CustomerNumber']))
    {
        $CustomerNumber=$_GET['CustomerNumber'];
        if(isset($_POST['submit']))
        {

            $crc_no = $_POST['crc_no'];
            $date_of_service = $_POST['date_of_service'];
            $date_of_interment = $_POST['date_of_interment'];
            $authorized_family = $_POST['authorized_family'];
            $rel_to_deceased = $_POST['rel_to_deceased'];
            $rel_address = $_POST['rel_address'];
            $service_phone_no = $_POST['service_phone_no'];
            $service_deceased = $_POST['service_deceased'];
            $service_type = $_POST['service_type'];
            $service_amount = $_POST['service_amount'];
            $less_service = $_POST['less_service'];
            $net_amount = $_POST['net_amount'];

            $query3=mysql_query("UPDATE records SET crc_no='$crc_no', date_of_service='$date_of_service', date_of_interment='$date_of_interment', authorized_family='$authorized_family', rel_to_deceased='$rel_to_deceased', rel_address='$rel_address', service_phone_no='$service_phone_no', service_deceased='$service_deceased', rel_address='$rel_address', service_phone_no='$service_phone_no', service_deceased='$service_deceased', service_type='$service_type', service_amount='$service_amount', less_service='$less_service', net_amount='$net_amount' WHERE CustomerNumber='$CustomerNumber'");
            if($query3)
            {
            header('location: fill.php');
            }
            }
            $query1=mysql_query("SELECT * FROM records where CustomerNumber='$CustomerNumber'");
            $query2=mysql_fetch_array($query1);
            ?>

这个PHP工作得很好。但是我想要的单选按钮(或者你可能建议的其他解决方案)是唯一不起作用的东西。

1 个答案:

答案 0 :(得分:0)

好。您的描述含糊不清,而且您的代码非常有限。 根据我的理解,你需要做的是,你需要检查哪个单选按钮被选中,然后你在ms_pricelist数据库中查询ms_name =你选中的单选按钮的行。然后使用该行的ms_price值。