使用新表单值

时间:2017-06-07 15:38:05

标签: php html mysql

我的任务是修复我们网站上的问题而且我不太精通SQL / PHP,但我们有一个使用首页数据表的系统,显示来自我们数据库的记录。当您单击该表中的序列号链接时,它会显示由指定记录中的数据填充的基于Web的表单/表。我现在被告知要使两个表可编辑,以便它仍然显示数据库中的当前字段,但这样我们可以选择更改它们,点击提交按钮并将新值保存到数据库。

下面的代码涵盖了首页中的实例以及从“staging”数据库表中选择右行的查询,并仅显示该记录中的信息。这很好用,因为我用输入标签升级代码,我现在可以编辑字段,但我还没有实现保存它们的选项。

如果我理解正确的话,我会在这个页面上创建一个“提交”按钮(虽然我想的是一个可能有每个html表的保存按钮的选项),当按下按钮时,我会附加一个SQL更新声明。

我在这里有两个问题:

  1. 如果我要编辑下面代码中的每个输入字段,运行该UPDATE语句以正确设置每个值的正确方法是什么?

  2. 如果你看到下面的内容,我有一个平均值的公式,我将结果放在$testFinalForm中。这都是在网页上完成的,并且数据库表中不存在该值。如果我要将testFinalForm添加到我的数据库表中,我也想保存该值。

  3. 同样,这不是我通常要做的事情,而且我有点不知所措,所以我只是希望得到一些有用的指导。

    if(isset($_GET['id'])) 
    {
    
    $query1 = "SELECT * FROM staging WHERE serialNumber = ".$_REQUEST['id'].";";
    $result1 = mysqli_query($connect,$query1);
    
    while($row = mysqli_fetch_array($result1)){
    ?>
    <form>
    
    <!--Meter Test (1) Table-->
    <div class="FirstMeterTable" style=" width:100%; clear: both;">
    <table style="width:100%; border:none;
    border-collapse:collapse;">
    
    
    
        <tr style="border:none;">
            <th style="border:none; text-align: left;" >Meter Test</th>
            <th style="border:none;">Test 1</th>
            <th style="border:none;">Test 2</th>
            <th style="border:none;">Test 3</th>
            <th style="border:none;">Test 4</th>
            <th style="border:none;">Test 5</th>
            <th style="border:none;">Test 6</th>
            <th style="border:none;">Test 7</th>
            <th style="border:none;">Test 8</th>
        </tr>
        <tr style="border: none;" >
            <td style="border:none; text-align: left;">Test Rate GPM: </td>
            <td><input type="text" value="<? echo $row['test1TestRateGPM'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test2TestRateGPM'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test3TestRateGPM'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test4TestRateGPM'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test5TestRateGPM'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test6TestRateGPM'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test7TestRateGPM'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test8TestRateGPM'];?>">&nbsp;</td>
    
        </tr>
        <tr>
            <td style="border:none; text-align: left;">Meter Volume: </td>
            <td><input type="text" value="<? echo $row['test1MeterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test2MeterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test3MeterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test4MeterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test5MeterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test6MeterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test7MeterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test8MeterVol'];?>">&nbsp;</td>
        </tr>
        <tr>
            <td style="border:none; text-align: left;">Tester Volume: </td>
            <td><input type="text" value="<? echo $row['test1TesterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test2TesterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test3TesterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test4TesterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test5TesterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test6TesterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test7TesterVol'];?>">&nbsp;</td>
            <td><input type="text" value="<? echo $row['test8TesterVol'];?>">&nbsp;</td>
        </tr>
        <tr>
            <td style="border:none; text-align: left;">Tester Accuracy: </td>
            <td><input type="text" value="<? echo $row['test1Accuracy'];?>">%&nbsp;</td>
            <td><input type="text" value="<? echo $row['test2Accuracy'];?>">%&nbsp;</td>
            <td><input type="text" value="<? echo $row['test3Accuracy'];?>">%&nbsp;</td>
            <td><input type="text" value="<? echo $row['test4Accuracy'];?>">%&nbsp;</td>
            <td><input type="text" value="<? echo $row['test5Accuracy'];?>">%&nbsp;</td>
            <td><input type="text" value="<? echo $row['test6Accuracy'];?>">%&nbsp;</td>
            <td><input type="text" value="<? echo $row['test7Accuracy'];?>">%&nbsp;</td>
            <td><input type="text" value="<? echo $row['test8Accuracy'];?>">%&nbsp;</td>
            <td style="border:none;">Overall</td>
        </tr>
        <tr>
            <td style="border:none; text-align: left;">Corrected Accuracy: </td>
    
                <?php 
            $sum=0;
    
    
            for($i=1; $i<=8; $i++){ 
    
    
            if($row["test".$i."TesterVol"] == 0){
            $row["test".$i."TesterVol"] = 0.001;
            }
    
            $testFormA = $row["test".$i."MeterVol"] / $row["test".$i."TesterVol"]; 
            $testFormB = $testFormA * $row["test".$i."Accuracy"]; 
            $testFinalForm = $testFormB;
            $sum += $testFinalForm; 
    
            ?>
            <td><?php echo round($testFinalForm,3) ?>%</td>
    
    
            <?php }
            $average = $sum / 7 ;
    
            ?>
    
            <td><?php echo round($average,5)?>%&nbsp;</td>
    
        </tr>
    </table>
    </div>
    <br>
    <br>
    </form>
    

0 个答案:

没有答案
相关问题