Jump to content
Parabot - Bot for Ikov, DreamScape, SoulPlay, RuneWild, and more
Sign in to follow this  
JKetelaar

[Short Tutorial] Simple calculator

Recommended Posts

A simple tutorial

<!-- This is the HTML part -->

<html>
<head><title>Simple PHP Calculator made by ParaDox</title></head>
<body>
<!-- For this calculator we will use post -->
<form method="post">
<!-- Here we make a form for our first number and we call it "firstnum" -->
First number:
 <input type="text" name="firstnum">
 <br>
 <!-- Here we make a dropdown box for the sort of operator -->
Sort operator:
 <select name="operator">
  <option>+</option>
  <option>-</option>
  <option>*</option>
  <option>/</option>
 </select>
 <br>
 <!-- Here we make a form for our second number and we call it "secondnum" -->
Second Number:
 <input type="text" name="secondnum">
 <br>
 <!-- Here we make our button to let the calculator do his job and we call the button "Calculate" -->
<input type="submit" name="calculate" value="Calculate">
</form>
</body>
</html>

 <!-- Now the PHP part -->

 <!-- Well this is easy to understand I think, LOL -->
<?php
$first=$_POST['firstnum'];
$second=$_POST['secondnum'];
$operator=$_POST['operator'];
 if ($operator=="+")
  {$total=$first + $second;}
 if ($operator=="-")
  {$total=$first - $second;}
 if ($operator=="*")
  {$total=$first * $second;}
 if ($operator=="/")
  {$total=$first / $second;}
 echo $total;
?>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...