Page 1 of 1
[SOLVED] PHP Math
Posted: Fri Mar 19, 2004 9:15 am
by bawla
i made this code to figure out some calculations
Code: Select all
<?php
$value1=$_GETї'value1'];
$value2=$_GETї'value2'];
$value3=$_GETї'value3'];
$value4=$_GETї'value4'];
$total1=($value1 + $value2 + $value3 / $value4);
echo ($total);
?>
but it doesnt seem to work, this is for a form that is in html
if u want to see an example
http://www.krunkdesigns.com/gtthing/gtthing.html
Posted: Fri Mar 19, 2004 9:18 am
by JayBird
echo ($total);
should be
echo ($total1);
Just a typo
Mark
Re: PHP Math
Posted: Fri Mar 19, 2004 9:30 am
by TheBentinel.com
bawla wrote:
Code: Select all
$total1=($value1 + $value2 + $value3 / $value4);
echo ($total);
Mark's right, you wanted $total1 there.
But also, I'm not sure about the precedence of +'s and /'s. To be safe, you should probably wrap parentheses around the parts you want done first, like:
$total1=( ($value1 + $value2 + $value3) / $value4);
or
$total1=($value1 + $value2 + ($value3 / $value4) );
I'm not sure what you're after so I don't know where they belong. Even if only for clarity of code, I'd stick them in.
but it doesnt seem to work, this is for a form that is in html
if u want to see an example
http://www.krunkdesigns.com/gtthing/gtthing.html
Posted: Fri Mar 19, 2004 9:51 am
by pickle
Ya, order of operations would divide $value3 by $value4, then do the addition.
Posted: Fri Mar 19, 2004 12:26 pm
by malcolmboston
i know its not vital
but in your scripts you should add some clauses as i went straight to the link and just clicked the submit button and i got a nasty error message (something you dont want users to see)
Code: Select all
if
(isset($variablename))
{
// this var is set
}
else
{
// this var is not set so we'll do something
exit();
}
just some food for thought
Posted: Fri Mar 19, 2004 6:20 pm
by bawla
thanks you guys i got it to work now