You are on page 1of 5

Main.

php
<?php

?>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->


    <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous">

    <title>Welcome To My Page</title>
  </head>
  <body>
 
<form name="form1" method="post" action="page2.php">
  <div class="mb-3">
    <label for="nama" class="form-label">Nama</label>
    <input type="text" class="form-control" name="nama" aria-
describedby="emailHelp">
   
  </div>
  <div class="mb-3">
    <label for="nokp" class="form-label">No. KP</label>
    <input type="text" class="form-control" name="nokp">
  </div>
 
  <button type="submit" class="btn btn-primary">Hantar</button>
</form>

</html>
Page2.php

<?php
session_start();
$nama = $_POST['nama'];
$nokp = $_POST['nokp'];

?>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->


    <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous">

    <title>Page 2</title>
  </head>
  <body>
  <form name="page2" method="post" action="page3.php">
  <table class="table">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">Nama</th>
      <th scope="col">No KP</th>
      <th scope="col">Bil. Subjek</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td><input type="text" class="form-control" name="nama[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="nokp[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="bil[]" aria-
describedby="emailHelp"></td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td><input type="text" class="form-control" name="nama[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="nokp[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="bil[]" aria-
describedby="emailHelp"></td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td><input type="text" class="form-control" name="nama[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="nokp[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="bil[]" aria-
describedby="emailHelp"></td>
    </tr>
    <tr>
      <th scope="row">4</th>
      <td><input type="text" class="form-control" name="nama[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="nokp[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="bil[]" aria-
describedby="emailHelp"></td>
    </tr>
    <tr>
      <th scope="row">5</th>
      <td><input type="text" class="form-control" name="nama[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="nokp[]" aria-
describedby="emailHelp"></td>
      <td><input type="text" class="form-control" name="bil[]" aria-
describedby="emailHelp"></td>
    </tr>
  </tbody>
</table>
<center><button type="submit" class="btn btn-primary">Kira</button></center>
</form>
</html>
Page3.php

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->


    <link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous">

    <title>Page 3</title>
  </head>
  <body>
 
  <table class="table">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">Nama</th>
      <th scope="col">No KP</th>
      <th scope="col">Bil. Subjek Diambil</th>
    </tr>
  </thead>
  <tbody>
<?php

    $nama = $_POST['nama'];
    $nokp = $_POST['nokp'];
    $bil   = ($_POST['bil']);
   
    $count=1;
    $total=0;
    $jumbyr=0;

        foreach ($nama as $id => $value)


        {
            $namas = ($nama[$id]);
            $nokps = ($nokp[$id]);
            $bils = ($bil[$id]);
 
          // print $nama[$id];
          // print $nokp[$id];
          // print $bil[$id];
            $jumbyr=$bil[$id]*10;
            $total=$total+$jumbyr;
       
?>

  <tr>
      <th scope="row"><?php print $count; ?></th>
      <td><?php print $nama[$id]; ?></td>
      <td><?php print $nokp[$id];?></td>
      <td><?php print $bil[$id];?></td>
    </tr>
   
<?php
      ++$count;
      }
     
?>
</tbody>
</table>

<?php cetak($total); ?>

<?php
function cetak($tot)
  {
      echo "Jumlah keseluruhan bayaran adalah RM : $tot";
  }
?>

</html>

You might also like