Jump to content

Simple Caluclator


hansman

Recommended Posts

Hey here is my script for a calculator, i cant figure out how to implement the subract and division features.

 

<form action="<? $_server['php_self']; ?>" method="get">
  <p>
  <input name="hello" type="text" size="5" /> 
<select name="how">
               <option value="*">X</option>
               <option value="+">+</option>
               <option value="-">-</option>
               <option value="/">%</option>
            </select>


  <input name="hello1" type="text" size="5" />
  </p>
  <p>
    <input name="" type="submit" />
  </p>
</form>
<?php
$_GET['hello'] = $hello;
$_GET['hello1'] = $hello1;
$_GET['how'] = $whatone;


echo $hello + $whatone + $hello1;


?>

Link to comment
https://forums.phpfreaks.com/topic/112658-simple-caluclator/
Share on other sites

Firstly:

You have the assignments backwards.  Switch these around:

$_GET['hello'] = $hello;

$_GET['hello1'] = $hello1;

$_GET['how'] = $whatone;

 

 

Secondly:

+ is not the concatenation operator in PHP, . is.

 

Third:

If you're just doing two numbers then use a switch statement.

Link to comment
https://forums.phpfreaks.com/topic/112658-simple-caluclator/#findComment-578560
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.