Jump to content

[SOLVED] Need some help with my calculator


simon.nor

Recommended Posts

Hey guys. I'm very new to php, and are trying to make sort of an calculator.

It is for a game so you can calculate the items stats in 4 different states of upgrade.

 

What it does is you input the stat, a number, and choose from a list witch upgrade it has, or none, and to what upgrade you would like to see the stat. It must also remove decimals from the answer, and this is what i have so far:

 

<html>

<body>

<?php

$green = 0.1 ;

$blue = 0.15 ;

$red = 0.25 ;

$white = 0.1 ;

 

if ( ($_POST[calc] == "no") && ($_POST[calto] == "no") )

{ $endresult = $_POST[value] ;

}

if ( ($_POST[calc] == "no") && ($_POST[calto] == "green") )

{ $endresult = $_POST[value] + ($_POST[val1] * $green ) ;

}

 

?>                     

<p align="left"><form action="calcgem.php" method="post">

<table>

<tr>

<td>

Current stat: <input type="text" name="value" size="10"></td>

</tr>

<tr><td>

Current Gem: <br></td>

</tr>

<tr><td>

<input type="radio" name="calc" value="no">No Gem

<input type="radio" name="calc" value="green">Green Gem

<input type="radio" name="calc" value="blue">Blue Gem

<input type="radio" name="calc" value="red">Red Gem

<input type="radio" name="calc" value="white">White Gem<br>

</tr>

<tr><td>

To:</td>

</tr>

<tr><td>

<input type="radio" name="calcto" value="no">No Gem

<input type="radio" name="calcto" value="green">Green Gem

<input type="radio" name="calcto" value="blue">Blue Gem

<input type="radio" name="calcto" value="red">Red Gem

<input type="radio" name="calcto" value="white">White Gem<br>

</tr>

<tr><td>

<?php echo  $endresult  ; ?>

 

</td>

</tr>

<tr><td>

<input type="submit" value="Calculate"></td></tr>

</form>

         

                     

 

</body>

</html>

 

 

i thought this was a good start, but i just get errors :-S

Parse error: parse error, unexpected '{' in /home/content/I/n/s/Instigator1985/html/calcgem.php on line 12

 

I have searched and read many calculator scripts and forum threads many places to try to help me with this, but i'm hoping now that you guys would point me in the right direction, and let me know what i do wrong here.

 

Thanks for your time

Link to comment
https://forums.phpfreaks.com/topic/42001-solved-need-some-help-with-my-calculator/
Share on other sites

try this

 

<html>
<body>
<?php
if(isset($_POST['submit'])){
$green = 0.1 ;
$blue = 0.15 ;
$red = 0.25 ;
$white = 0.1 ;

if ( ($_POST['calc'] == "no") && ($_POST['calcto'] == "no") )
{ $endresult = $_POST[value] ;
}
if ( ($_POST['calc'] == "no") && ($_POST['calcto'] == "green") )
{ $endresult = $_POST['value'] + ($_POST['value'] * $green ) ;
}
echo  number_format($endresult,0);
} else {
?>
<p align="left"><form action="" method="post">
<table>
<tr>
<td>
Current stat: <input type="text" name="value" size="10"></td>
</tr>
<tr><td>
Current Gem:
</td>
</tr>
<tr><td>
<input type="radio" name="calc" value="no">No Gem
<input type="radio" name="calc" value="green">Green Gem
<input type="radio" name="calc" value="blue">Blue Gem
<input type="radio" name="calc" value="red">Red Gem
<input type="radio" name="calc" value="white">White Gem

</tr>
<tr><td>
To:</td>
</tr>
<tr><td>
<input type="radio" name="calcto" value="no">No Gem
<input type="radio" name="calcto" value="green">Green Gem
<input type="radio" name="calcto" value="blue">Blue Gem
<input type="radio" name="calcto" value="red">Red Gem
<input type="radio" name="calcto" value="white">White Gem

</tr>
<tr><td>

</td>
</tr>
<tr><td>
<input type="submit" name=submit value="Calculate"></td></tr>
</form>
<?php
}
?>
</body>
</html>

 

Ray

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.