Tuesday, November 27, 2012

Form php

Membuat formulir Toko sepeda

File sepeda.php
<body>
<form name="form1" method="post" action="sepeda_output.php">
  <table width="367" border="0" align="center">
    <tr>
      <td colspan="3"><div align="center">TOKO SEPEDA <br>
      IMAM CYCL</div></td>
    </tr>
    <tr>
      <td width="144">Kode sepeda </td>
      <td width="6">:</td>
      <td width="203"><select name="kode" id="kode">
        <option value="Poligon" selected>001</option>
        <option value="BMX">002</option>
        <option value="Wim Cycle">003</option>
      </select></td>
    </tr>
    <tr>
      <td>Jenis</td>
      <td>:</td>
      <td><select name="jenis" id="jenis">
        <option value="Lipat">Lipat</option>
        <option value="Gunung" selected>Gunung</option>
        <option value="Santai">Santai</option>
                                                            </select></td>
    </tr>
    <tr>
      <td>Jumlah Pesan </td>
      <td>:</td>
      <td><input name="jumlah" type="text" id="jumlah"></td>
    </tr>
    <tr>
      <td>Status Pengiriman </td>
      <td>:</td>
      <td><input name="status" type="radio" value="Antar">
      Antar
      <input name="status" type="radio" value="Non Antar">
      Non Antar </td>
    </tr>
    <tr>
      <td colspan="3"><div align="center">
        <input type="submit" name="Submit" value="Proses">
         <input type="submit" name="Submit" value="Batal">
      </div></td>
    </tr>
  </table>
</form>
</body>
</html>

File proses sepeda_output.php :

<body>
<?php
if($_POST['kode']=='001')
{
            if($_POST['jenis']=='Lipat')
            {
            $harga=1200000;
            }
            elseif($_POST['jenis']=='Gunung')
            {
            $harga=1000000;
            }
            else
            {
            $harga=1300000;
            }
}
elseif($_POST['kode']=='002')
{
            if($_POST['jenis']=='Lipat')
            {
            $harga=900000;
            }
            elseif($_POST['jenis']=='Gunung')
            {
            $harga=1100000;
            }
            else
            {
            $harga=1200000;
            }
}
else
{
            if($_POST['jenis']=='Lipat')
            {
            $harga=1300000;
            }
            elseif($_POST['jenis']=='Gunung')
            {
            $harga=1200000;
            }
            else
            {
            $harga=1000000;
            }
}
$hargatotal=$jumlah*$harga;

if($_POST['status']=='Antar')
{
$ongkir=50000;
}
else
{
$ongkir=0;
}

$jml=$hargatotal+$ongkir;
           
echo"
<form name='form1' method='post' action=''>
  <table width='367' border='0' align='center'>
    <tr>
      <td colspan='3'><div align='center'>TOKO SEPEDA <br>
        IMAM CYCL</div></td>
    </tr>
    <tr>
      <td width='144'>Kode sepeda </td>
      <td width='6'>:</td>
      <td>$kode</td>
    </tr>
    <tr>
      <td>Jenis</td>
      <td>:</td>
      <td>$jenis</td>
    </tr>
    <tr>
      <td>Jumlah Pesan </td>
      <td>:</td>
      <td>$jumlah</td>
    </tr>
    <tr>
      <td>Status Pengiriman </td>
      <td>:</td>
      <td>$status</td>
    </tr>
             <tr>
      <td>Harga </td>
      <td>:</td>
      <td>$hargatotal</td>
    </tr>
             <tr>
      <td>Ongkos Kirim </td>
      <td>:</td>
      <td>$ongkir</td>
    </tr>
                         <tr>
      <td>   </td>
      <td>:</td>
      <td>==========</td>
    </tr>
              <tr>
      <td>Jumlah </td>
      <td>:</td>
      <td>$jml</td>
    </tr>
           
    <tr>
      <td colspan='3'><div align='center'>
            <a href=sepeda.php>
                                    --input lagi--
                                    </a>
          <p>--- TERIMA KASIH --- </p>
      </div></td>
    </tr>
  </table>";
?>
</body>
</html>

Comments
0 Comments

0 comments:

Post a Comment