php - 从表中提取值

标签 php html mysql

我如何在total_cost_acquistion中使用total_no_of_units和cost_per_unit中输入的值,即(总成本=单位*每单位成本)请建议我任何方法来做到这一点..total_cost_acquistion的值必须在no_of_units后立即显示并给出了每单位成本......

<?php
    require_once "session.php";
?>
<?php
    include('connection.php');
    if (isset($_POST['submit'])){
      $sl_no =$_POST['sl_no'];
      $dec =$_POST['description'];
      $loctn =$_POST['location'];
      $ref_no =$_POST['reference_no'];
      $d_of_aqstn =$_POST['date_of_acquisation'];
      $t_of_un =$_POST['total_no_of_units'];
      $cst_p_un =$_POST['cost_per_unit'];
      $tl_cost_aqstn =$_POST['total_cost_of_acquistion'];
      $lf_ast_pr_cdl =$_POST['life_of_assets_per_codal'];
      $no_yr_ast_use =$_POST['no_year_assets_use'];
      $rt_deprtn =$_POST['rate_depreciation'];
      $act_deprtn =$_POST['accumulate_depreciation'];
      $val_as_on = $_POST['value_as_on'];
      $remks =$_POST['remarks'];

      $query = "insert into form(sl_no, description, location, reference_no, date_of_acquisation, total_no_of_units, cost_per_unit, total_cost_of_acquistion, life_of_assets_per_codal, no_year_assets_use, rate_depreciation, accumulate_depreciation, value_as_on, remarks)
     values('$sl_no','$dec','$loctn','$ref_no','$d_of_aqstn','$t_of_un','$cst_p_un','$tl_cost_aqstn','$lf_ast_pr_cdl','$no_yr_ast_use','$rt_deprtn','$act_deprtn','$val_as_on','$remks')";
     $retval = mysql_query($query,$con);
     if(!$retval )
       {
        die('Could not enter data: ' . mysql_error());
       }
     mysql_close($con);
    }
  ?>
  <html>
  <head>
       <meta charset = "utf-8">
       <link rel = "stylesheet"
            href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

         <script type = "text/javascript"
            src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

         <script type = "text/javascript"
            src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>

         <script>
            $(function() {
               $( "#datepicker" ).datepicker();
            });
         </script>
       <title>Add a Form</title>
     </head>
      <body>
    <h1 align="center"><strong>FIXED ASSET REGISTER</strong></h1>
    <b align="center">Welcome : <i><?php echo $_SESSION['login_user']; ?> </i></b>
      <br>

        <form method="POST" action="<?php $PHP_SELF ?>">
        <div align="center">
            <table width=100%  cellpadding="5" cellspacing="2" align="center">
              <tr>
                <td colspan="2" align="center"> <h2><strong>FORM-10</strong></h2></td>
              </tr>
              <tr>
                <td align="right"> <strong>Serial_No:</strong></td>
                <td><input type="text"  name="sl_no"  placeholder="Serial_no" required></td>
              </tr>

              <tr>
                <td align="right"> <strong>Description :</strong></td>
                <td><input type="text"  name="description"  placeholder="description" required></td>
              </tr>
              <tr>
                <td align="right"> <strong>Location:</strong></td>
                <td><input type="text" name="location"  placeholder="location" required></td>
              </tr>
              <tr>
                <td align="right"> <strong>Reference_no:</strong></td>
                <td><input type="text"  name="reference_no"  placeholder="reference_no" required></td>
              </tr>

             <tr>
                <td align="right"> <strong>Date_of_Acquisition:</strong></td>
                <td><input type="text"  name="date_of_acquisation" id = "datepicker" placeholder="date_of_acquisation" required></td>
              </tr>

                <tr>

              <td align="right"> <strong>Total_no_of_Units:</strong></td>
                <td><input type="text"  name="total_no_of_units"  placeholder="total_no_of_units" required></td>

              </tr>

                <tr>
              <td align="right"> <strong>Cost per Unit:</strong></td>
                <td><input type="text" name="cost_per_unit" placeholder="cost_per_unit" required></td>

              </tr>

                <tr>

              <td align="right"> <strong>Total Acquisition Cost:</strong></td>
                <td><input type="text" name="total_cost_of_acquistion" placeholder="total_cost_of_acquistion" required></td>


              </tr>

                <tr>
                        <td align="right"> <strong>Asset Life:</strong></td>
                <td><input type="text" name="life_of_assets_per_codal" placeholder="life_of_assets_per_codal" required></td>
                </tr>

                <tr>
                        <td align="right"> <strong>Years asset used:</strong></td>
                <td><input type="text" name="no_year_assets_use" placeholder="no_of_year_assets_use" required></td>
                </tr>

                <tr>
                        <td align="right"> <strong>Depriciation Rate:</strong></td>
                <td><input type="text" name="rate_depreciation" placeholder="rate_depreciation" required></td>
                </tr>

                <tr>
                        <td align="right"> <strong>Accumulated Depriciation:</strong></td>
                <td><input type="text" name="accumulate_depreciation" placeholder="accumulate_depreciation_till_31/03/2016" required></td>
                </tr>

                <tr>
                        <td align="right"> <strong>Valuation:</strong></td>
                <td><input type="text" name="value_as_on" placeholder="value_as_on_31/03/2016" required></td>
                </tr>

                <tr>
                        <td align="right"> <strong>Remarks:</strong></td>
                <td><input type="text" name="remarks" placeholder="remarks" ></td>
        </tr>




            <!--  <tr>
                <td align="right"> <strong>Status: </strong></td>
                <td><select name="status" required>
                    <option></option>
                    <option>New</option>
                    <option>Old</option>
                    <option>Lost</option>
                    <option>Damage</option>
                    <option>Subject for Replacement</option>
                    <option>Archive</option>
                </select>
                </td>
            </tr>-->
              <tr>
                <td colspan="2" align="center"><input type='submit' value=' Save ' name='submit'>

              </tr>
            </table>
            <h4 align="right"><a href="mainpage1.php">BACK</a></h4>
        </div>
         </form>

    </body>
    </html>

最佳答案

我想这就是你想要的:

<?php
require_once "session.php";
?>
<?php
include('connection.php');
if (isset($_POST['submit'])){
$sl_no =$_POST['sl_no'];
$dec =$_POST['description'];
$loctn =$_POST['location'];
$ref_no =$_POST['reference_no'];
$d_of_aqstn =$_POST['date_of_acquisation'];
$t_of_un =$_POST['total_no_of_units'];
$cst_p_un =$_POST['cost_per_unit'];
$tl_cost_aqstn =$_POST['total_cost_of_acquistion'];
$lf_ast_pr_cdl =$_POST['life_of_assets_per_codal'];
$no_yr_ast_use =$_POST['no_year_assets_use'];
$rt_deprtn =$_POST['rate_depreciation'];
$act_deprtn =$_POST['accumulate_depreciation'];
$val_as_on = $_POST['value_as_on'];
$remks =$_POST['remarks'];

$query = "insert into form(sl_no, description, location, reference_no, date_of_acquisation, total_no_of_units, cost_per_unit, total_cost_of_acquistion, life_of_assets_per_codal, no_year_assets_use, rate_depreciation, accumulate_depreciation, value_as_on, remarks)
 values('$sl_no','$dec','$loctn','$ref_no','$d_of_aqstn','$t_of_un','$cst_p_un','$tl_cost_aqstn','$lf_ast_pr_cdl','$no_yr_ast_use','$rt_deprtn','$act_deprtn','$val_as_on','$remks')";
 $retval = mysql_query($query,$con);
 if(!$retval )
   {
    die('Could not enter data: ' . mysql_error());
   }
 mysql_close($con);
}
  ?>
  <html>
 <head>
   <meta charset = "utf-8">
   <link rel = "stylesheet"
        href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

     <script type = "text/javascript"
        src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

     <script type = "text/javascript"
        src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>

     <script>
        $(function() {
           $( "#datepicker" ).datepicker();
        });
     </script>
   <title>Add a Form</title>
 </head>
  <body>
<h1 align="center"><strong>FIXED ASSET REGISTER</strong></h1>
<b align="center">Welcome : <i><?php echo $_SESSION['login_user']; ?> </i></b>
  <br>

    <form method="POST" action="<?php $PHP_SELF ?>">
    <div align="center">
        <table width=100%  cellpadding="5" cellspacing="2" align="center">
          <tr>
            <td colspan="2" align="center"> <h2><strong>FORM-10</strong></h2></td>
          </tr>
          <tr>
            <td align="right"> <strong>Serial_No:</strong></td>
            <td><input type="text"  name="sl_no"  placeholder="Serial_no" required></td>
          </tr>

          <tr>
            <td align="right"> <strong>Description :</strong></td>
            <td><input type="text"  name="description"  placeholder="description" required></td>
          </tr>
          <tr>
            <td align="right"> <strong>Location:</strong></td>
            <td><input type="text" name="location"  placeholder="location" required></td>
          </tr>
          <tr>
            <td align="right"> <strong>Reference_no:</strong></td>
            <td><input type="text"  name="reference_no"  placeholder="reference_no" required></td>
          </tr>

         <tr>
            <td align="right"> <strong>Date_of_Acquisition:</strong></td>
            <td><input type="text"  name="date_of_acquisation" id = "datepicker" placeholder="date_of_acquisation" required></td>
          </tr>

            <tr>

          <td align="right"> <strong>Total_no_of_Units:</strong></td>
            <td><input type="text"  name="total_no_of_units" id="total_no_of_units" onkeyup="calculate()" placeholder="total_no_of_units" required></td>

          </tr>

            <tr>
          <td align="right"> <strong>Cost per Unit:</strong></td>
            <td><input type="text" name="cost_per_unit" id="cost_per_unit" onkeyup="calculate()" placeholder="cost_per_unit" required></td>

          </tr>

            <tr>

          <td align="right"> <strong>Total Acquisition Cost:</strong></td>
            <td><input type="text" name="total_cost_of_acquistion" id="total_cost_of_acquistion" placeholder="total_cost_of_acquistion" required></td>


          </tr>

            <tr>
                    <td align="right"> <strong>Asset Life:</strong></td>
            <td><input type="text" name="life_of_assets_per_codal" placeholder="life_of_assets_per_codal" required></td>
            </tr>

            <tr>
                    <td align="right"> <strong>Years asset used:</strong></td>
            <td><input type="text" name="no_year_assets_use" placeholder="no_of_year_assets_use" required></td>
            </tr>

            <tr>
                    <td align="right"> <strong>Depriciation Rate:</strong></td>
            <td><input type="text" name="rate_depreciation" placeholder="rate_depreciation" required></td>
            </tr>

            <tr>
                    <td align="right"> <strong>Accumulated Depriciation:</strong></td>
            <td><input type="text" name="accumulate_depreciation" placeholder="accumulate_depreciation_till_31/03/2016" required></td>
            </tr>

            <tr>
                    <td align="right"> <strong>Valuation:</strong></td>
            <td><input type="text" name="value_as_on" placeholder="value_as_on_31/03/2016" required></td>
            </tr>

            <tr>
                    <td align="right"> <strong>Remarks:</strong></td>
            <td><input type="text" name="remarks" placeholder="remarks" ></td>
    </tr>




        <!--  <tr>
            <td align="right"> <strong>Status: </strong></td>
            <td><select name="status" required>
                <option></option>
                <option>New</option>
                <option>Old</option>
                <option>Lost</option>
                <option>Damage</option>
                <option>Subject for Replacement</option>
                <option>Archive</option>
            </select>
            </td>
        </tr>-->
          <tr>
            <td colspan="2" align="center"><input type='submit' value=' Save ' name='submit'>

          </tr>
        </table>
        <h4 align="right"><a href="mainpage1.php">BACK</a></h4>
    </div>
     </form>
<script>
    function calculate(){
        var number = $('#total_no_of_units').val();
        var unitCost = $('#cost_per_unit').val();
        var totalCost = $('#total_cost_of_acquistion').val();
        if(number=='' || unitCost==''){
            $('#total_cost_of_acquistion').val('0');
            return false;
        }
        else{
            $('#total_cost_of_acquistion').val(number*unitCost);
        }
    }
</script>
</body>
</html>

关于php - 从表中提取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44593333/

相关文章:

php - 如何抓取网站上的动态内容并保存?

php - 在这种情况下(PHP/MySQL)可以不清理用户输入吗?

javascript - 防止在不指定宽度的情况下 float 包装

html - Bootstrap 初学者 : Grid Problems

返回时具有不同列的 MySQL 联合

mysql - 在 Ubuntu 上安装 luaSQL

php - 创建访问者唯一 ID?

c# - 如何在给定视频 ID 的情况下获取 youtube channel ID 和名称

javascript - 如何通过 jQuery 隐藏两个特定 id 之间的内容?

python - 知道一个 SQL 请求的结果是否必须是另一个 SQL 请求结果的一部分