Welcome to Katz - Pinoy Underground Forum

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?
  • Compact Safety Notice
  • Weekly Grants Lottery is live! Win a 20,000 ₪ jackpot — tickets are just 30 ₪, drawn every week. Buy your tickets »

Simple PHP Calculator

J 986

jovs011

Corporal
Member
Access
Member
Access
4 Year Silver Member 4y Silver
Joined
Jul 16, 2022
Messages
742
Reaction score
13
Points
18
Age
27
Location
cavite
grants
₲2,004
Just wanna share to you the code for a simple PHP calculator, hope it helps especially those who are learning PHP.

PHP:
<?php
if(isset($_POST['calc']) && $_POST['calc'] == "Calculate")
{
    $_POST['int1']=trim((int)$_POST['int1']);
    $_POST['int2']=trim((int)$_POST['int2']);
    $_POST['math']=$_POST['math'];
   
    $int1=$_POST['int1'];
    $int2=$_POST['int2'];
    $math=$_POST['math'];
    if(!empty($math) && $math == 1)
    {
        $math="+";
        $tot=$int1+$int2;
    }
    elseif(!empty($math) && $math == 2)
    {
        $math="-";
        $tot=$int1-$int2;
    }
    elseif(!empty($math) && $math == 3)
    {
        $math="/";
        $tot=$int1/$int2;
    }
    elseif(!empty($math) && $math == 4)
    {
        $math="*";
        $tot=($int1*$int2);
    }
   
   
    print "$int1 $math $int2 = $tot";
    exit;
}
else
{
        //this is html embedded inside PHP
    print "<form action='".$_SERVER['PHP_SELF']."' method='post'>
    number 1:<input type='text' name='int1' /><br/>
    number 2:<input type='text' name='int2' /><br/>
    Math Symbol:<select name='math'>
    <option value='1'>Add</option>
    <option value='2'>Subtract</option>
    <option value='3'>Divide</option>
    <option value='4'>Multiply</option>
    </select><br/>
    <input type='submit' name='calc' value='Calculate' />
    </form>";
}
?>
Thank you
 
PUSSY_SLAYER 19.1K

PUSSY_SLAYER

EXPERT COLLECTOR OF HOT GIRLS
Ardent
Access
Ardent
Access
Power User
Community Legend
4 Year Silver Member 4y Silver
Joined
Feb 26, 2022
Messages
2,870
Reaction score
7,768
Points
113
Location
NEPAL
grants
₲16,490
Just wanna share to you the code for a simple PHP calculator, hope it helps especially those who are learning PHP.

PHP:
<?php
if(isset($_POST['calc']) && $_POST['calc'] == "Calculate")
{
    $_POST['int1']=trim((int)$_POST['int1']);
    $_POST['int2']=trim((int)$_POST['int2']);
    $_POST['math']=$_POST['math'];
   
    $int1=$_POST['int1'];
    $int2=$_POST['int2'];
    $math=$_POST['math'];
    if(!empty($math) && $math == 1)
    {
        $math="+";
        $tot=$int1+$int2;
    }
    elseif(!empty($math) && $math == 2)
    {
        $math="-";
        $tot=$int1-$int2;
    }
    elseif(!empty($math) && $math == 3)
    {
        $math="/";
        $tot=$int1/$int2;
    }
    elseif(!empty($math) && $math == 4)
    {
        $math="*";
        $tot=($int1*$int2);
    }
   
   
    print "$int1 $math $int2 = $tot";
    exit;
}
else
{
        //this is html embedded inside PHP
    print "<form action='".$_SERVER['PHP_SELF']."' method='post'>
    number 1:<input type='text' name='int1' /><br/>
    number 2:<input type='text' name='int2' /><br/>
    Math Symbol:<select name='math'>
    <option value='1'>Add</option>
    <option value='2'>Subtract</option>
    <option value='3'>Divide</option>
    <option value='4'>Multiply</option>
    </select><br/>
    <input type='submit' name='calc' value='Calculate' />
    </form>";
}
?>
Laking tulong sa newbie na developer ito thank you
 
A 0

ayamen

Abecedarian
BANNED
Member
Access
Banned
Joined
Sep 4, 2022
Messages
75
Reaction score
0
Points
6
Age
28
Location
Sorsogon
grants
₲152
Just wanna share to you the code for a simple PHP calculator, hope it helps especially those who are learning PHP.

PHP:
<?php
if(isset($_POST['calc']) && $_POST['calc'] == "Calculate")
{
    $_POST['int1']=trim((int)$_POST['int1']);
    $_POST['int2']=trim((int)$_POST['int2']);
    $_POST['math']=$_POST['math'];
   
    $int1=$_POST['int1'];
    $int2=$_POST['int2'];
    $math=$_POST['math'];
    if(!empty($math) && $math == 1)
    {
        $math="+";
        $tot=$int1+$int2;
    }
    elseif(!empty($math) && $math == 2)
    {
        $math="-";
        $tot=$int1-$int2;
    }
    elseif(!empty($math) && $math == 3)
    {
        $math="/";
        $tot=$int1/$int2;
    }
    elseif(!empty($math) && $math == 4)
    {
        $math="*";
        $tot=($int1*$int2);
    }
   
   
    print "$int1 $math $int2 = $tot";
    exit;
}
else
{
        //this is html embedded inside PHP
    print "<form action='".$_SERVER['PHP_SELF']."' method='post'>
    number 1:<input type='text' name='int1' /><br/>
    number 2:<input type='text' name='int2' /><br/>
    Math Symbol:<select name='math'>
    <option value='1'>Add</option>
    <option value='2'>Subtract</option>
    <option value='3'>Divide</option>
    <option value='4'>Multiply</option>
    </select><br/>
    <input type='submit' name='calc' value='Calculate' />
    </form>";
}
?>
angas nito man thanks
 
W 0

wrath098

Squaddie
BANNED
Member
Access
Banned
Joined
Sep 13, 2022
Messages
280
Reaction score
4
Points
18
Age
76
Location
USQ
grants
₲528
Just wanna share to you the code for a simple PHP calculator, hope it helps especially those who are learning PHP.

PHP:
<?php
if(isset($_POST['calc']) && $_POST['calc'] == "Calculate")
{
    $_POST['int1']=trim((int)$_POST['int1']);
    $_POST['int2']=trim((int)$_POST['int2']);
    $_POST['math']=$_POST['math'];
   
    $int1=$_POST['int1'];
    $int2=$_POST['int2'];
    $math=$_POST['math'];
    if(!empty($math) && $math == 1)
    {
        $math="+";
        $tot=$int1+$int2;
    }
    elseif(!empty($math) && $math == 2)
    {
        $math="-";
        $tot=$int1-$int2;
    }
    elseif(!empty($math) && $math == 3)
    {
        $math="/";
        $tot=$int1/$int2;
    }
    elseif(!empty($math) && $math == 4)
    {
        $math="*";
        $tot=($int1*$int2);
    }
   
   
    print "$int1 $math $int2 = $tot";
    exit;
}
else
{
        //this is html embedded inside PHP
    print "<form action='".$_SERVER['PHP_SELF']."' method='post'>
    number 1:<input type='text' name='int1' /><br/>
    number 2:<input type='text' name='int2' /><br/>
    Math Symbol:<select name='math'>
    <option value='1'>Add</option>
    <option value='2'>Subtract</option>
    <option value='3'>Divide</option>
    <option value='4'>Multiply</option>
    </select><br/>
    <input type='submit' name='calc' value='Calculate' />
    </form>";
}
?>
Yes pasado na ako neto
 
Y 191

yobabski

Transcendent
Member
Access
Member
Access
3 Year Silver Member 3y Silver
Joined
Oct 13, 2022
Messages
35
Reaction score
0
Points
6
Age
32
Location
San Juan
grants
₲243
Just wanna share to you the code for a simple PHP calculator, hope it helps especially those who are learning PHP.

PHP:
<?php
if(isset($_POST['calc']) && $_POST['calc'] == "Calculate")
{
    $_POST['int1']=trim((int)$_POST['int1']);
    $_POST['int2']=trim((int)$_POST['int2']);
    $_POST['math']=$_POST['math'];
   
    $int1=$_POST['int1'];
    $int2=$_POST['int2'];
    $math=$_POST['math'];
    if(!empty($math) && $math == 1)
    {
        $math="+";
        $tot=$int1+$int2;
    }
    elseif(!empty($math) && $math == 2)
    {
        $math="-";
        $tot=$int1-$int2;
    }
    elseif(!empty($math) && $math == 3)
    {
        $math="/";
        $tot=$int1/$int2;
    }
    elseif(!empty($math) && $math == 4)
    {
        $math="*";
        $tot=($int1*$int2);
    }
   
   
    print "$int1 $math $int2 = $tot";
    exit;
}
else
{
        //this is html embedded inside PHP
    print "<form action='".$_SERVER['PHP_SELF']."' method='post'>
    number 1:<input type='text' name='int1' /><br/>
    number 2:<input type='text' name='int2' /><br/>
    Math Symbol:<select name='math'>
    <option value='1'>Add</option>
    <option value='2'>Subtract</option>
    <option value='3'>Divide</option>
    <option value='4'>Multiply</option>
    </select><br/>
    <input type='submit' name='calc' value='Calculate' />
    </form>";
}
?>
Gonna try this
 
Top Bottom