Learn How to Create a Currency Converter Using PHP

1
5197
currency-converter

A Currency Converter is a calculator that converts the value or quantity of one currency into the relative values or quantities of other currencies. For example, if you lived in the US and were traveling to another country, you would need to know the per dollar exchange rate for the currency of the country you were visiting. You would need to know the dollar- euro conversion, if you were traveling to certain parts of Europe, the dollar-pound conversion if you were in traveling in the United Kingdom, the dollar-yen conversion if you were traveling in Japan, the Canadian dollar – U.S. dollar conversion if you were traveling in Canada or the Swiss francs-dollar conversion if you were traveling in Switzerland.

A currency converter stores the most recent market valuations of the world’s currencies, which allows individuals to compare the value of one currency against those of others in the database.

In this article, we are going to build a simple currency calculator which is based on PHP as well as we are going to use the if condition and the basic html syntax. For this we need XAMPP or WAMPP.

Steps for installing Xampp: –
1. You have to visit the following link https://www.apachefriends.org/index.html Once you open the link, you have to download the installation file according to your operating system. Once the installation is finished, you have to go your installation drive ( I used the C drive) and click on Xampp folder. After clicking on XAMPP, you will be able to see multiple folders, click on htdocs.

In this folder, you can add your code. I attached the screen-shot, have a look:
htdocs
2. Now, we have to create a folder inside the htdocs named as converter. After that we have to create a file named currencyconvertor.php inside the converter folder. You can see the attached screen-shot:
converter

Steps for Implementation:
1. Now its time to start our coding part. Firstly we are going to design our form using basic html element after that we want to add the data in table format so I added table tag inside form. You will use the code stated below:

This will be your output:
currency-converter

2. Now after designing the form, we have to write a logic for currency converter. We used the IF condition as well as we used isset (). It is used to check whether a variable is set or not. If a variable is already unset with unset() function, it will no longer be set. The isset() function returns false if testing variable contains a NULL value.

After that, we are going to use $_POST(). The PHP provides $_POST associative array to access all the sent information using POST method. I attached the code below:

3. Now its time to add some CSS into your project so we are going to add the CSS part in header part using the style tag.

After adding html, css and php, your code look like this:

currency-converter-page
convert-currency
I hope this has been helpful for you guys in understanding a how to create a currency convertor using php.. Goodluck!

1 COMMENT

  1. Philippine Money Changer

    Amount:

    Currency:

    Korean Won
    US Dollar
    Singapore Dollar

    <?php
    $currency=$_POST['currency'];
    $amount=$_POST['amount'];

    if ($currency=='won')
    {
    echo "Your Converted Amount is:“;
    echo $amount*21.51941;
    }
    else if($currency==’usd’)
    {
    echo “Your Converted Amount is:“;
    echo amount*50.6112;
    }
    else ($currency==’sd’)
    {
    echo “Your Converted Amount is:“;
    echo amount*37.4800;
    }

    ?>

    Hi! I am novice on using PHP. This is so far my second output but doesn’t work at all.

    When I check the localhost, it says
    Parse error: syntax error, unexpected ‘{‘ in C:\xampp\htdocs\Activity 2\Converter.php on line 18.

    Why is that? Need your help.
    Thank you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here