How to Create a Simple Order Transaction Form with PHP

In this article I want to provide a simple tutorial on how to create an Order Transaction Form program in php without a database, so this program is specifically for beginners who are new to the php programming language like me.

Transactions on a website are activities carried out by users that can cause changes to data. A transaction functions to record all data changes and prevent data from being lost or damaged, after the transaction is completed, the data is usually stored in a database, but in this tutorial I replace the role of the database into an array which incidentally can only temporarily store data.

Here are the tools / software that must be prepared to create an order transaction form in this php:

  • Web Server = Xampp (windows), Lampp (linux), Mampp (mac) or others.
  • Web Browser = (Mozilla, Chrome, or others).
  • Text Editor = (Sublime, Notepad ++, or others).

Simple PHP Program Order Transaction Form

This is what the order form looks like which we will create later

And the following is a display of the output results

The Booking Transaction Form Program has the theme of booking hotel rentals and the program has several inputs, including:

  • Booking Date (With HTML datepicker).
  • Customer Name.
  • No Identity.
  • Room Type (Combo Box).
  • Duration of stay.
  • As well as the Save and Cancel buttons.

Also read: How to Create Simple Input and Output Forms with PHP

Apart from having some input, the program also has a logic that can determine the amount of the discount based on the per-night rental price. With a list of rental prices as follows:

  • Deluxe Room: Rp. 850,000 / night
  • Superior Room: Rp. 500,000 / night

And a discount will be given if it meets the following conditions:

  • Get a 10% discount from the total payment, if the total cost of paying the room rental is more than (>) 1,500,000.
  • Get a discount of 20% of the total payment, if the total cost of the rent is paid rooms over (>) 2,000,000.

This Order Transaction program uses a For loop for array calls, and also If else to determine the discount amount. Then don’t forget to function so that the source code is more structured.

Here’s the source code

<?php
function hasil() {
	$tanggal = $_POST['tanggal'];
	$namcus = $_POST['namcus'];
	$noId = $_POST['noId'];
	$durasi = $_POST['durasi'];
	$tipe = $_POST['tipe'];
	$deluxe = 850000;
	$superior = 500000;
	$diskon;
	$total;
	error_reporting(0);

	//Output program dan Pemanggilan Array
	foreach ($namcus as $key => $val) {
		?>
          <table border="0" width="500" cellpadding="1" cellspacing="1" >

            <tr>
              <td><?php echo '&nbsp Tanggal Booking'; ?></td>
              <td><?php echo '&nbsp : '; ?></td>
              <td><?php echo '&nbsp' . $tanggal; ?></td>
            </tr>

            <tr>
              <td><?php echo '&nbsp Nama Customer'; ?></td>
              <td><?php echo '&nbsp : '; ?></td>
              <td><?php echo '&nbsp' . $namcus[$key]; ?></td>
            </tr>

            <tr>
              <td><?php echo '&nbsp No Identitas'; ?></td>
              <td><?php echo '&nbsp : '; ?></td>
              <td><?php echo '&nbsp' . $noId[$key]; ?></td>
            </tr>

            <tr>
              <td><?php echo '&nbsp Tipe Kamar'; ?></td>
              <td><?php echo '&nbsp : '; ?></td>
              <td><?php echo '&nbsp' . $tipe; ?></td>
            </tr>

            <tr>
              <td><?php echo '&nbsp Durasi Penginapan'; ?></td>
              <td><?php echo '&nbsp : '; ?></td>
              <td><?php echo '&nbsp' . $durasi . ' Malam'; ?></td>
            </tr>

            <tr>
              <td><?php echo '&nbsp Diskon'; ?></td>
              <td><?php echo '&nbsp : '; ?></td>
              <td>
                <?php
//Menentukan Diskon
		if ($tipe) {
			if ($durasi == "") {
				echo "Durasi belum diisi";
			} elseif ($tipe == "Deluxe") {
				$hasil = $deluxe * $durasi;
				$hasil;
			} elseif ($tipe == "Superior") {
				$hasil = $superior * $durasi;
				$hasil;
			}

			if ($hasil > 2000000) {
				$diskon = (20 / 100) * $hasil;
				$total = $hasil - $diskon;
				echo "&nbspPotongan diskon 20%";
			} elseif ($hasil > 1500000) {
				$diskon = (10 / 100) * $hasil;
				$total = $hasil - $diskon;
				echo "&nbspPotongan diskon 10%";
			} else {
				echo "&nbspAnda tidak berhak mendapatkan diskon";
			}
		}?>
              </td>
            </tr>

            <tr>
              <td><?php echo '&nbsp Total Bayar'; ?></td>
              <td><?php echo '&nbsp : '; ?></td>
              <td>
                <?php
//Menentukan Total Biaya
		if ($tipe) {
			if ($durasi == "") {
				echo "Durasi belum diisi";
			} elseif ($tipe == "1") {
				$hasil = $deluxe * $durasi;
				$hasil;
			} elseif ($tipe == "2") {
				$hasil = $superior * $durasi;
				$hasil;
			}

			if ($hasil > 2000000) {
				$diskon = (20 / 100) * $hasil;
				$total = $hasil - $diskon;
				echo "&nbsp" . $total;
			} elseif ($hasil > 1500000) {
				$diskon = (10 / 100) * $hasil;
				$total = $hasil - $diskon;
				echo "&nbsp" . $total;
			} else {
				echo "&nbsp" . $hasil;
			}
		}?>
              </td>
            </tr>
          </table>
            <?php
}
}?>

<!-- Tampilan Awal Form Pemesanan -->
 <html>
 <form method="POST" name="frmpost" action="">
 <table width="500" border="1" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <th><h2> Form Pemesanan </h2></th>
  </tr>
  <tr>
    <td>
      <table width="500" border="0" cellpadding="6" cellspacing="6" align="center">

        <tr height="40">
            <td width="200" valign="center">Tanggal Booking</td>
            <td width="10" valign="center"> : </td>
            <td><input type="date" name="tanggal"></td>
        </tr>

        <tr height="30">
          <td width="200" valign="center">Nama Customer</td>
          <td width="10" valign="center"> : </td>
          <td><input name="namcus[]" type="text" size="20" /></td>
        </tr>

        <tr height="30">
          <td width="200" valign="center">No Identitas</td>
          <td width="10" valign="center"> : </td>
          <td><input name="noId[]" type="text" size="40" /></td>
        </tr>

        <tr height="30">
          <td width="200" valign="center">Tipe Kamar</td>
          <td width="10" valign="center"> : </td>
          <td>
            <select name="tipe">
              <option name="-" value="-" hidden>-</option>
              <option name="deluxe" value="Deluxe">Deluxe</option>
              <option name="superior" value="Superior">Superior</option>
            </select>
          </td>
        </tr>

        <tr height="30">
          <td width="200" valign="center">Durasi Menginap</td>
          <td width="10" valign="center"> : </td>
          <td><input  name="durasi" type="text" size="10"  /> Malam</td>
        </tr>

        <tr>
          <td align="right" colspan="2"><input type="submit" name="btnOk" value="Simpan" /></td>
          <td><input type="reset" name="btnCancel" value="Cancel" /></td>
        </tr>

      </table>
      </table>
      <br>
      <br>

 <table width="500" border="0" cellpadding="0" cellspacing="0" align="center">
        <tr>
          <td>
            <?php
//Pemanggilan Function
hasil();
?>
          </td>
        </tr>
 </table>

</form>
</center>
</html>

Save the source code in xampp > htdocs with the format namaFile.php, make sure your xampp is active then please call on localhost using your web browser.

The display when the program has been run will look like the image below

This is the simple PHP program for the order transaction form, hopefully this is useful.

Leave a Reply

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