如何在php中进行表单计算


How to do calculation in forms in php?

<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>      

按价格的倍数金额

<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;
?>