使用PHP中的用户输入的公式计算值 [英] Calculating values with formulae from user input in PHP

查看:325
本文介绍了使用PHP中的用户输入的公式计算值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用从输入框中获得的值ampMin,voltMin和hastMin来做一个方程式...

I want to do an equation using the values I get from the input boxes called ampMin, voltMin and hastMin...

我不确定这是否是语法问题,或者我的处理方法是否完全错误.这是一个公式的示例,该示例如何与Excel配合使用.

I'm not sure if it's a syntax problem or my method of approach is plain wrong.. Here's is an example of how the equation should look and work like with Excel.

我做错了什么?谢谢您的时间!

What am I doing wrong? Thank you for your time!

值得一提的是,整个代码块都在"strckenergi.php"中.

worth mentioning is that the whole block of code is within "strckenergi.php".

<html>
<title>Sträckenergi</title>
<body>
    <h3>Svetsmetod: 111</h3>
    <h4><i>Med K=0.8</i></h4>
    <pre>
        <form method="post" action="strckenergi.php">
            Amp. Min <input type="text" name="ampMin">  Volt. Min <input type ="text" name="voltMin"> Hast. Min <input type="text" name="hastMin"> </pre>
        <?php
        echo "kJ/mm (minimum) = " . $qMin
        $qMin = ( $ampMin * $voltMin ) / (( $hastMin * 1000 ) / $hastMin * 0.8));
        ?>  
</body>
</html>

推荐答案

这有效.

<html>
<title>Sträckenergi</title>
<body>
<h3>Svetsmetod: 111</h3>
<h4><i>Med K=0.8</i></h4>
     <pre>
    <form method="post" action="form.php">
Amp. Min <input type="text" name="ampMin">  Volt. Min <input type ="text"       name="voltMin"> Hast. Min <input type="text" name="hastMin">
    <input type="submit" value="submit"> </pre>
</form>

<?php
    if($_POST){

        $voltMin = $_POST['voltMin'];
        $ampMin = $_POST['ampMin'];
        $hastMin = $_POST['hastMin'];

        $qMin = ( $ampMin * $voltMin ) / ( $hastMin * 1000 ) / $hastMin * 0.8;
        echo "kJ/mm (minimum) = " . $qMin;
    }
    ?>

这篇关于使用PHP中的用户输入的公式计算值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆