Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 保存依赖于选定字段的数据_Php - Fatal编程技术网

Php 保存依赖于选定字段的数据

Php 保存依赖于选定字段的数据,php,Php,我想根据在选择菜单上选择的选项来保存数据,它的选项附带了一定的百分比,我尝试使用下面的代码,但它只保存一个值,不管选择了哪个选项 我曾尝试使用Steven Wanderski的条件字段,但它只在所有选择中保存一个值 my index.php <?php require_once('config.php'); require_once('function.php'); ?> <!DOCTYPE html> <h

我想根据在选择菜单上选择的选项来保存数据,它的选项附带了一定的百分比,我尝试使用下面的代码,但它只保存一个值,不管选择了哪个选项

我曾尝试使用Steven Wanderski的条件字段,但它只在所有选择中保存一个值

my index.php

  <?php
    require_once('config.php');
    require_once('function.php');
    ?>



    <!DOCTYPE html>
        <html>
        <head>


        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

          <script
            src="https://code.jquery.com/jquery-3.4.1.min.js"
            integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
            crossorigin="anonymous"></script>
            <script src="js/conditional-field.min.js"></script>



        </head>
        <body>


    <div class="container mt-3">

        <form role="form" method="post" action="process.php">

           <?php $grant="20";
           $direct_cost="100";
           $discounts="100";
           $overhead_costs="70";
           ?>

            <p class="h4 mb-4">Supplier Spends</p>

            <div class="form-row mb-4">
                <div class="col">

                    <label for="prog_description">Name of the Programme:</label><span style="color: red !important; display: inline; float: none;">*</span>
                    <input type="text" id="prog_description" name="prog_description" class="form-control" placeholder="enter name of the programme embarked on" required>
                </div>

            </div>

            <label for="type_of_contrib">Type of Contribution:</label><span style="color: red !important; display: inl`enter code here`ine; float: none;">*</span>
            <select name="type_of_contrib" id="TypeOfContribution" class="TypeOfContribution form-control mb-4"  required>
            <option value="">--select type of contribution--</option>
            <option value="Grant Contribution">Grant Contribution</option>
        <option value="Direct cost incurred">Direct cost incurred</option>
        <option value="discounts"> Discounts</option>
        <option value="Overheads costs">Overheads costs</option>
        <option value="Standard Loan">Standard Loan</option>
        <option value="Lower Interest Rate">Lower Interest Rate</option>
        <option value="Guarantees Provided">Guarantees Provided</option>
        <option value="Minority Investment">Minority Investment</option>
        <option value="Services at no Cost">Services at no Cost</option>
        <option value="Services at a Discount">Services at a Discount</option>
        <option value="Time of Employees">Time of Employees</option>
        <option value="Shorter payment periods">Shorter payment periods</option>
        <option value="Investment with lower Dividend">Investment with lower Dividend</option>
        </select>


        <div class="benefit form-row mb-4 ">
            <div class="col">

                <label for="Grant Contribution">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor" class="form-control" placeholder="benefit factor" value="<?php echo $grant;?>"  readonly="readonly" required>

            </div>

        </div>


        <div class="benefit2 form-row mb-4">
            <div class="col">

                <label for="Direct cost incurred">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor" class="form-control" placeholder="benefit factor" value="<?php echo $direct_cost;?>" readonly="readonly" required>
            </div>

        </div>



        <div class="benefit3 form-row mb-4">
            <div class="col">

                <label for="Discounts">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor"class="form-control" placeholder="benefit factor" value="<?php echo $discounts;?>" readonly="readonly" required>
            </div>

        </div>


        <div class="benefit4 form-row mb-4">
            <div class="col">

                <label for="Overheads costs">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor"class="form-control" placeholder="benefit factor" value="<?php echo $overhead_costs;?>" readonly="readonly"  required>
            </div>

        </div>



        <div class="benefit5 form-row mb-4">
            <div class="col">

                <label for="Standard Loan">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor"class="form-control" placeholder="benefit factor" value="70" readonly="readonly"  required>
            </div>

        </div>

        <div class="benefit6 form-row mb-4">
            <div class="col">

                <label for="Lower Interest Rate">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor"class="form-control" placeholder="benefit factor" value="50" readonly="readonly"  required>
            </div>

        </div>


        <div class="benefit7 form-row mb-4">
            <div class="col">

                <label for="Guarantees Provided">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor" class="form-control" placeholder="benefit factor" value="3" readonly="readonly"   required>
            </div>

        </div>


        <div class="benefit8 form-row mb-4">
            <div class="col">

                <label for="Minority Investment">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor"class="form-control" placeholder="benefit factor" value="70" readonly="readonly"  required>
            </div>

        </div>


        <div class="benefit9 form-row mb-4">
            <div class="col">

                <label for="Services at no Cost">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor" class="form-control" placeholder="benefit factor" value="60" readonly="readonly"  required>
            </div>

        </div>

        <div class="benefit10 form-row mb-4">
            <div class="col">

                <label for="Services at a Discount">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor" class="form-control" placeholder="benefit factor" value="60" readonly="readonly"  required>
            </div>

        </div>
        <div class="benefit11 form-row mb-4">
            <div class="col">

                <label for="Time of Employees">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor" class="form-control" placeholder="benefit factor" value="60" readonly="readonly"  required>
            </div>

        </div>
        <div class="benefit12 form-row mb-4" value="100";>
            <div class="col">

                <label for="shorter payment periods">Benefit Factor:</label><span style="color: red !important; display: inline; float: none;">*</span>
                <input type="text" id="benefit_factor" name="benefit_factor" class="form-control" placeholder="benefit factor" value="15" readonly="readonly" required>
            </div>

        </div>




        <label for="budgeted_spend">Budgeted Spend:</label>
        <input type="number" id="budgeted_spend" name="budgeted_spend" class="form-control mb-4" placeholder="Budgeted Spend" required>


        <label for="actual_amount">Actual Amount Spent:</label><span style="color: red !important; display: inline; float: none;">*</span>
        <input type="number" id="actual_amount" name="actual_amount" class="form-control mb-4" placeholder="Actual Amount Spent" required>

        <label for="current_status">Status of the programme:</label><span style="color: red !important; display: inline; float: none;">*</span>
        <select name="current_status" id="current_status" class="status form-control mb-4"  required>
        <option disabled  selected>--select current status--</option>
        <option value="started">started</option>
        <option value="in_progress">in-progress</option>
        <option value="completed">completed</option>
        <option value="cancelled">cancelled</option>
        </select>

        <label for="anticipated_completion">Anticipated Completion Date:</label>
        <input type="date" id="anticipated_completion" name="anticipated_completion" class="form-control mb-4" required>


        <button class="btn btn-info my-4 btn-block" type="submit">Save Data</button>




    </form>

<br>

<?php
            get_all_records();
            ?>


</div>
<script>
$(document).ready(function(){
new ConditionalField({
  control: '.TypeOfContribution',
  visibility: {
    'Grant Contribution': '.benefit',
    'Direct cost incurred': '.benefit2',
    'discounts': '.benefit3',
    'Overheads costs': '.benefit4',
    'Standard Loan': '.benefit5',
    'Lower Interest Rate': '.benefit6',
    'Guarantees Provided': '.benefit7',
    'Minority Investment': '.benefit8',
    'Services at no Cost': '.benefit9',
    'Services at a Discount': '.benefit10',
    'Time of Employees': '.benefit11',
    'Shorter payment periods': '.benefit12',

    }

   });
});

</script>

?>

供应商花费

节目名称:* 捐款类型:* --选择供款类型-- 捐款 直接成本 折扣 间接费用 标准贷款 低利率 提供的担保 少数股东投资 免费服务 打折服务 员工时间 缩短付款期 低股息投资 效益因素:*
表单包含许多具有相同id和名称的输入字段。id在文档中必须是唯一的(没有两个元素可以共享一个id)。关于名称,多个输入可以共享同一个名称,但您必须使用
效益系数[]
(末尾为[])将所有这些输入作为数组发送。如果没有,则只使用/提交一个(它发现的第一个)。此外,隐藏的表单(无显示)仍将是表单的一部分并已提交。非常感谢,让我尝试一下,您能至少帮助我进行代码示例什么的代码示例?您所需要做的就是为每个输入提供一个唯一的名称和id。好的,谢谢,但我想将所有福利系数数据保存在一个字段中,具体取决于贡献的tupe\uselected@MagnusEriksson考虑把你的评论转换成答案。这可能会帮助其他人解决同样的问题。