Jump to content

Coding help


jrc713

Recommended Posts

So I put this in the wrong place :-[ so ill try again,

I need to write a code to add the price of five items with a subtotal, with tax, and then a grand total.

What is the best way to do this? :confused:

Every way I have tried isnt working

  PLEASEEEEEE HELP!!!

Using crimson editor

 


<?php


$item1 = floatval($_POST['item1']);
$item2 = floatval($_POST['item2']);
$item3 = floatval($_POST['item3']);
$item4 = floatval($_POST['item4']);
$item5 = floatval($_POST['item5']);

$tax = ".10"; // 10%

if (isset($_POST['submit']))
{

$subtotal = $item1+$item2+$item3+$item4+$item5;
$taxAmount = $subtotal * $tax;
$total = $subtotal+$taxAmount;

echo "Subtotal: $subtotal<br>
  Tax: $taxAmount<br>
  Total: $total";
  
}

?>
<style>
input{display:block;}
</style>
<form action="" method="post">
<input type="text" name="item1" />
<input type="text" name="item2" />
<input type="text" name="item3" />
<input type="text" name="item4" />
<input type="text" name="item5" />
<input type="submit" value="Add" name="submit" />
</form>

 

Not great, but it works quick. Tell your teacher I sayz hi!  :P

 

Just messing with ya, sort of.

Link to comment
https://forums.phpfreaks.com/topic/224584-coding-help/#findComment-1160144
Share on other sites

;) Thank you so much for you're help you are awesome.  The teacher did give some examples but the editor that i am using isn't showing color so I can't tell if what I am typing is correct or not.  This is my first class and I am sooooo green when it come to writing code. :shrug:

P.S.  Sorry for posting in the wrong spot this is my first time in this forum.

Link to comment
https://forums.phpfreaks.com/topic/224584-coding-help/#findComment-1160148
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.