如何在PHP中的表单中进行计算?

时间:2015-06-21 14:53:04

标签: javascript php html

<form action="" method="post">
Color: <input type="text" name="Color"><br>
  ProductID: <input type="text" name="ProductID"><br>
  <!-- Receiver Nam: <input type="text" name="last_name"><br> -->
  Amount: <input type="text" name="Amount"><br>
  Price: <input type="text" name="Price"><br>
  <input type="submit" name="submit" value="Submit" class="button red">

</form>      

按价格计算多个金额

1 个答案:

答案 0 :(得分:2)

<form action="yourpage.php" method="post">
Color: <input type="text" name="Color"><br>
  ProductID: <input type="text" name="ProductID"><br>
  <!-- Receiver Nam: <input type="text" name="last_name"><br> -->
  Amount: <input type="text" name="Amount"><br>
  Price: <input type="text" name="Price"><br>
  <input type="submit" name="submit" value="Submit" class="button red">

</form>  



<?php

/* get the posted data */
$productId = $_POST['ProductID'];
$lastName = $_POST['last_name'];
$amount = $_POST['Amount'];
$price = $_POST['Price'];

$totalPrice = ($amount*$price); /*multiply the amount by the price */

/* print the result */
echo "Hi ".$lastName;
echo "Total Price is: ".$totalPrice;

?>