Learn PHP at Repl.it: Calculate Discount


This article discusses the creation of a simple program or application, namely calculating a discount (rebate) from the total price using the PHP programming language and the Repl.it online text compiler. Here, you don’t need to install any additional applications to run the program on the PHP server, unless you use a MySQL database because Repl.it doesn’t support the MySQL component.

Repl.it is suitable for those of you who do not have their own PC or laptop or have their own PC or laptop but are inadequate to install several supporting applications in creating programs or web applications with the PHP programming language. This is suitable for those of you who are still beginners in learning the PHP programming language.

For special source code for making applications or simple web-based programs to calculate discounts (rebates) with PHP, you can develop from this source code to be even better. You can follow this tutorial to create a simple program to calculate discounts with PHP and the online text editor Repl.it.


1. Visit the site Repl.it.

2. Login by entering the correct username or email and password.

3. Click Create Reply.

4. Choose the Type PHP Web Server and give the project name hitungdiskon.

5. After that, click Create Repl.

6. Delete the entire command code in index.php.

7. Create a program or web application to calculate the discount listed below.

<title>Aplikasi sederhana Menghitung Diskon</title> 
<h2 align="center">Aplikasi sederhana Menghitung Diskon.</h2> 
<form action="" method="post"> 
<p>Masukkan Nilai Total Harga : Rp <input type="text" name="harga"> </p> 
<p>Masukkan Nilai Potongan Harga (Diskon) : <input type="text" name="diskon"> %</p> 
<input type="hidden" name="hitung" value="hitung"> 
<input type="submit" value="HITUNG"> </form> 

//Menampung harga yang telah diinput oleh teks input yang 'name=harga'. 
$harga = $_POST['harga'];

//Menampung persentase diskon yang telah diinput oleh teks input yang 'name=diskon'.
$diskon = $_POST['diskon'];

//Rumus untuk menghitung diskon. 
$potonganharga = $harga * ($diskon/100);

//Rumus untuk menghitung total harga setelah dikurangi diskon.
$hasil = $harga - $potonganharga;

//Menampilkan hasil perhitungan diskon. 
echo "Nilai Total Harga Semula : Rp ".$harga."<br/>"; 
echo "Nilai Potongan Harga (Diskon) : ".$diskon."%<br/>"; 
echo "Hasil Hitung Diskon : Rp ".$potonganharga."<br/>"; 
echo "Nilai Total Harga : Rp ".$hasil."<br/>"; 

8. Click Run.

9. Enter the total value of the price and the percentage for the discount, click Enter.

10. Here are the results.


You can also implement the project using a custom domain that can integrate the Repl.it project with your own domain name through DNS Management. An important point in calculating discounts (rebates) is that you analyze and determine the appropriate discount formula in a case study around us.

Try, you really study the source code above until you understand the use and function of each of the command codes and don’t just copy-paste without understanding the use and function of each of the command codes.


You can develop a simple web application or program to calculate discounts with the PHP programming language that suits your creativity in creating or developing the application or website so that it can produce something useful such as an online shop website.


Leave a comment

Your email address will not be published.