HomePHP

Creating a Currency Converter in PHP – Video Tutorials

Like Tweet Pin it Share Share Email
currency converter in PHPMy last tutorial on this blog was on creating a simple calculator in PHP, and already I’ve shared a complete series of video tutorials about PHP, however, you may have come across different websites on the internet where you see online currency converters. These kind of currency converters may easily be created with PHP, and I’ve video tutorials for you today to create a simple currency converter in PHP. I’ll also be giving you the source code which I used during these video tutorials. As this will be a simple converter in design, however, you may design it using CSS and HTML. But the main aim is to create such application and enhance your development skills. Now let’s start creating it without delay.

How to Create A currency converter in PHP?

This question is unnecessary now, because we’ve already discussed it (((:))). And we are now going to create the converter in PHP, and you might know PHP gives you much power to create complex applications, more than a Facebook application. We’ll create this application simply by using IF Statements in PHP and we don’t need to use MySQL etc, because we’re not gonna sending any data to the server.
For creating a converter in PHP you’ll need to create a page called “converter.php” in which you’ll first create a simple converter using HTML form tag and some input tags, and after creating that you’ll need to write a PHP script for that converter. You can learn this all from below tutorials.
First watch below video tutorials to understand creating currency converter, and below the tutorials, you can find the source code which was used in these video tutorials:
Hey, Having watched video tutorials, I’m hopefully saying you’ve understood what I wanted to teach. Now let’s have a look at the source code of this application, this is the HTML part of the converter:

<html>
<head>
<title> PHP currecny Convertor</title>
</head>
<body>
<form align=’center’ action=’convertor.php’ method=’post’>
Enter Amount:<input type=’text’ name=’amount’>
From:<select name=’cur1′>
<option>Dollar</option>
<option>Pound</option>
</select>
To:<select name=’cur2′>
<option>Indian</option>
<option>PKR</option>
<option>Afghani</option>
</select>
<input type=’submit’ name=’submit’ value=’Convert Now’>
</form>
</body>
</html>

Now when you created a form with HTML, then you need to create a PHP script for making this converter to work properly, here is the PHP script for this:

<?php
if(isset($_POST[‘submit’])){
$amount = $_POST[‘amount’];
$cur1 = $_POST[‘cur1’];
$cur2 = $_POST[‘cur2’];

if($cur1==”Dollar” AND $cur2==”PKR”){
echo “<center><b>Your Converted Amount is:</b><br></center>”;
echo “<center>” . $amount*97.5 . “</center>”;
}

if($cur1==”Dollar” AND $cur2==”Indian”){
echo “<center><b>Your Converted Amount is:</b><br></center>”;
echo “<center>” . $amount*48 . “</center>”;
}

if($cur1==”Dollar” AND $cur2==”Afghani”){
echo “<center><b>Your Converted Amount is:</b><br></center>”;
echo “<center>” . $amount*54 . “</center>”;
}

if($cur1==”Pound” AND $cur2==”PKR”){
echo “<center><b>Your Converted Amount is:</b><br></center>”;
echo “<center>” . $amount*160 . “</center>”;
}

if($cur1==”Pound” AND $cur2==”Indian”){
echo “<center><b>Your Converted Amount is:</b><br></center>”;
echo “<center>” . $amount*120 . “</center>”;
}

if($cur1==”Pound” AND $cur2==”Afghani”){
echo “<center><b>Your Converted Amount is:</b><br></center>”;
echo “<center>” . $amount*100 . “</center>”;
} }
?>

I’ve used few currencies in this application, however, you may use as many as you want, jut increase the options in select box and increase the variables in PHP.

So how was this tutorial? did you learn something in PHP? and do love programming in PHP? and will I be a perfect web developer in the future or not? Your opinion is warmly welcomed! Take Care!

Comments (11)

Speak Your Mind