Currency Converter App In PHP | CampCodes

Currency Converter App in PHP

June 1, 2020
PHP
currency converter in php

In this tutorial, we will create a Currency Converter App using PHP. This code will convert the current money to a different country when the user submits the form value. The system uses a PHP POST to call a specific method that sends the cost and save it to the currency options by calculating with unique formulas. This is a user-friendly kind of program feel free to modify it.

We will be using PHP as a scripting language and interpreter that is used primarily on any web server, including xamp, wamp, etc. It is being used to any popular websites, and it has a modern technology that can easily be used by the next generation.

Getting Started:

First, you have to download & install XAMPP or any local server that run PHP scripts. Here’s the link for XAMPP server https://www.apachefriends.org/index.html.

And, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the copy of the way and write it into your text editor, then save it as index.php.

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
        <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
    </head>
<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodster</a>
        </div>
    </nav>
    <div class="col-md-3"></div>
    <div class="col-md-6 well">
        <h3 class="text-primary">Currency Converter App Using PHP Source Code</h3>
        <hr style="border-top:1px dotted #ccc;"/>
        <div class="col-md-6 alert alert-danger">
            <form method="POST" action="">
                <div class="form-inline">
                    <select name="val" class="form-control">
                        <option value="PHP">PHP</option>
                        <option value="USD">USD</option>
                    </select>
                    <input class="form-control" type="number" name="digit"/>
                </div>	
                <br />
                <div class="form-inline">
                    <label>Select Currency: </label>
                    <select name="currency" required="required" class="form-control">
                        <option value="">Select an option</option>
                        <option value="USD">USD</option>
                        <option value="Euro">Euro</option>
                        <option value="PHP">PHP</option>
                        <option value="Japanese Yen">Japanese Yen</option>
                        <option value="Pound">Pound</option>
                    </select>
                    <br /><br />
                    <center><button type="submit" name="convert" class="btn btn-primary form-control" style="width:30%;">Convert</button></center>
                    <br />
                </div>	
                    <?php require 'convert.php'?>
            </form>
        </div>
    </div>
</body>
</html>

Creating the Main Function

This code contains the main function of the application. This code will convert the value when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as convert.php

<?php
    if(ISSET($_POST['convert'])){
        $val = $_POST['val'];
        $digit = $_POST['digit'];
        $currency = $_POST['currency'];
 
 
        if($val=="PHP" && $currency=="USD"){
            $output = $digit * 51.52;
            echo"<center><label class='text-success' style='font-size:25px;'>$".$output."</label></center>";
        }else if($val=="PHP" && $currency=="Euro"){
            $output = $digit * 63.62;
            echo"<center><label class='text-success' style='font-size:25px;'>€".$output."</label></center>";
        }else if($val=="PHP" && $currency=="PHP"){
            $output = $digit;
            echo"<center><label class='text-success' style='font-size:25px;'>₱".$output."</label></center>";
        }else if($val=="PHP" && $currency=="Japanese Yen"){
            $output = $digit * 0.47;
            echo"<center><label class='text-success' style='font-size:25px;'>¥".$output."</label></center>";
        }else if($val=="PHP" && $currency=="Pound"){
            $output = $digit * 65.83;
            echo"<center><label class='text-success' style='font-size:25px;'>£".$output."</label></center>";
        }else if($val=="USD" && $currency=="USD"){
            $output = $digit;
            echo"<center><label class='text-success' style='font-size:25px;'>$".$output."</label></center>";
        }else if($val=="USD" && $currency=="Euro"){
            $output = $digit*0.89;
            echo"<center><label class='text-success' style='font-size:25px;'>€".$output."</label></center>";
        }else if($val=="USD" && $currency=="PHP"){
            $output = $digit/51.52;
            echo"<center><label class='text-success' style='font-size:25px;'>₱".$output."</label></center>";
        }else if($val=="USD" && $currency=="Japanese Yen"){
            $output = $digit*107.72;
            echo"<center><label class='text-success' style='font-size:25px;'>¥".$output."</label></center>";
        }else if($val=="USD" && $currency=="Pound"){
            $output = $digit*1.30;
            echo"<center><label class='text-success' style='font-size:25px;'>£".$output."</label></center>";
        }
    }
?>
https://www.campcodes.com/

This is a free education portal. You can use every source code in your project without asking permission to the author. Share our website to everyone to make our community of programmers grow more.

Leave a Reply

Your email address will not be published. Required fields are marked *