Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8369835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:45:24+00:00 2026-06-09T13:45:24+00:00

I have to program a currency converter in php, which converts the following currencys:

  • 0

I have to program a currency converter in php, which converts the following currencys:

EUR -> USD
EUR -> GBP

The code must have a good structure and clear. My code looks like this:

In index.php, I write the html inputs as follow:

                <select name="fT">
                    <option value="euro-usd@EUR-USD">EUR -> USD</option>
                    <option value="euro-gbp@EUR-GBP">EUR -> GBP</option>
                <select>
                   <input type="text" name="amount" id="amount" value="">
                   <input type="submit"/>

convert.php looks like this:

<?php
include ("functions.php");
$fT = $_POST['fT'];
$amount = $_POST['amount'];

$valueAndText = explode('@', $fromTo);
$fromTo = $valueAndText[0];
$text = explode('-', $valueAndText[1]);
$from = $text[0];
$to = $text[1];

echo convertCurr($fT, $amount) ;
?>

Any suggestion for improving this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:45:26+00:00Added an answer on June 9, 2026 at 1:45 pm

    You can place the share prices in a config file that you can replace with each change. I am considering that you do want to store the data in files and not in a DB.

    The config file can look like:

    <?php
     $config['usd-eur']=1.2;
     $config['usd-gbp']=0.5;
    ?>
    

    Name this file as config.php,and place it with you scripts then include it.

    <?php
     require_once('config.php');
    ?>
    

    Regarding the $_POST variables you need to escape them to protect yourself from MySQL and XSS attacks.

    You can use this function:

    <?php
    function filter($data) {
    $data = trim(htmlentities(strip_tags($data)));
    if (get_magic_quotes_gpc())
        $data = stripslashes($data);
    
    $data = mysql_real_escape_string($data);
    
    return $data;
    }?>
    

    Then loop through your POST variables:

    foreach($_POST as $key => $value) {
     $mydata[$key] = filter($value);
    }
    

    Once more thing is the amount of processing you perform to detect the selection for the $fromto variable.

    Why not to do it like that:

    <select name="fromTo">
      <option value="1">(EUR) ---> (USD)</option>
      <option value="2">(EUR) ---> (GBP)</option>
    </select>
    

    Then perform a Switch-Case statement

    <?php
     switch($mydata['fromTo']){
      case 1:
       $from='euro';
       $to='usd';
       break;
      case 2:
       $from='euro';
       $to='gbp';
       break;
     }
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have program which prints all char from char_min to char_max here is code
I have program, that must interact with a console program before my program can
I have a program which creates JButtons which are then added to a JPanel
I have program which writes to database which folders are full or empty. Now
Here is my situation: I have program A which looks like this: Fmfile IF
I have a SQL database with rows containing prices of EUR/USD for a given
I have program which reads MSMQ using GetAllMessages but it does not remove messages
I have a program for which I plan to use a lot of Timer
I have program which contains a for loop inside another for loop, which produces
I have program which loads an assembly using Asssembly.LoadFrom method. Some time later I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.