Pemograman Web Dinamis (Catalog) PHP dan MySql #2

berlanjut dari postingan sebelumnya mengenai Project PWD kelompok kami..
sebelumnya kita telah membuat halaman beranda…nah sekarang kita akan membuat halaman pemesanan

dan masih sama seperti sebelumnya silahkan buat file kerja dengan nama *pesan (*tidak direkomendasikan)

silahkan copas code berikut


<?php

include 'koneksi.php';
?>
<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="utf-8">
 <title>TP PWD</title>
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta name="description" content="">
 <meta name="author" content="">

<!-- Le styles -->
 <link href="css/bootstrap.css" rel="stylesheet" />
 <link href="css/style.css" rel="stylesheet" />

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
 <!--[if lt IE 9]>
 <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
 <![endif]-->

<!-- Le fav and touch icons -->
 <link rel="shortcut icon" href="../assets/ico/favicon.ico">
 <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
 <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
 <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
 <link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
 </head>

<body>


 <div class="container">
 <div class="row">
 <div class="span12">


 <div class="navbar">
 <div class="navbar-inner">
 <div class="container">
 <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 </a>
 <a class="brand" href="#">TP Pemrograman Web</a>
 <div class="nav-collapse">
 <ul class="nav">
 <li class="active"><a href="index.php">Home</a></li>
 <li><a href="#">Profil</a></li>
 <li class="dropdown">
 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Shop <b class="caret"></b></a>
 <ul class="dropdown-menu">


 </ul>
 </li>

 </ul>


 <form class="navbar-search pull-left" action="" novalidate="novalidate">
 <input type="text" class="search-query span2" placeholder="Search">
 </form>
 </div><!-- /.nav-collapse -->
 </div>
 </div><!-- /navbar-inner -->
 </div>

 </div>



 </div>

 <div class="row">
 <div class="span12">
 <div id="myCarousel" class="carousel slide">
 <div class="carousel-inner">
 <div class="item active">
 <img src="img/slide.jpg" alt="">
 <div class="carousel-caption">
 <h4>First Thumbnail label</h4>
 <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
 </div>
 </div>

 <div class="item">
 <img src="img/slide.jpg" alt="">
 <div class="carousel-caption">
 <h4>Second Thumbnail label</h4>
 <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
 </div>
 </div>

 </div>
 <a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a>
 <a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a>
 </div>

 </div>
 </div>
 <div class="row content">
 <div class="span12">
 <?php

 if(isset($_POST['kode_plg']) && isset($_POST['jumlah']) && isset($_POST['idproduk'])) :
 $queryBarang = mysql_query('SELECT * FROM produk WHERE idproduk='.$_POST['idproduk']);
 $barang = mysql_fetch_object($queryBarang);
 if($barang->stok < 1) : echo '<script>alert("stok barang habis");</script>'; header('Location:index.php');
 endif;
 $now = date('Y-m-d');
 $total_bayar = intval($barang->harga) * intval($_POST['jumlah']);
 $hae = mysql_query("INSERT INTO pemesanan (`idproduk`,`kode_plg`,`tgl` , `jumlah` , `total_bayar`)
 VALUES ('$_POST[idproduk]' , '$_POST[kode_plg]' , $now , '$_POST[jumlah]',
 $total_bayar
 )
 ");
 if($hae):

mysql_query("UPDATE produk SET stok=stok-$_POST[jumlah] WHERE idproduk=".$_POST['idproduk']);

echo "<p>pelanggan dengan kode pelanggan : ".$_POST['kode_plg']."</p>";
 echo "<p>anda harus membayar sejumlah ". $total_bayar."</p>";
 echo "<a href='index.php' >Kembali</a>";
 exit();

endif;

endif;

if(!isset($_GET['idproduk']) && $_GET['idproduk'] == '') header('Location:index.php');

$queryBarang = mysql_query('SELECT * FROM produk ');
 $barang = mysql_fetch_object($queryBarang);
 //$query= mysql_query('SELECT * FROM `produk`' );
 //$produk = mysql_fetch_object($query);
 ?>
 <table>
 <tr>
 <tr><td>Kategori </td> <td> : <?php echo $barang->nama; ?></td></tr>
 <tr><td>Harga</td> <td> : <?php echo $barang->harga; ?></td> </tr>
 <tr><td>Stock </td> <td> : <?php echo $barang->merek; ?></td></tr>
 </table>

<br>
 <form method="post" action="pemesanan.php">

<table>
 <tr>
 <td> Kode Pelanggan </td>
 <td> <input type="text" name="kode_plg"> </td>
 </tr>

 <tr>
 <td> Jumlah barang </td>
 <td> <input type="text" name="jumlah">
 <input type="hidden" name="idproduk" value="<?php echo $barang->idproduk;?>">
 </td>
 </tr>

 </table>


 <input type="submit" value="Pesan">

 </form>
 </div>
 </div>


<div class="row footer">

 <div class="span12 clearmarg" id="testimonial">


 <div id="myCarousel" class="carousel slide">
 <div class="carousel-inner">

 <div class="item active">
 <div class="row box center">
 <div class="span4 marg5">
 <p>Ahsan Anwar S.</p>
 <p>10018133</p>
 <p> <a href="#"><i class="icon-big icon-facebook-sign"></i> Facebook </a>
 <a href="#"><i class="icon-big icon-twitter-sign"></i> Twitter </a> </p>


 </div>
 <div class="span4 marg5">
 <p>Annisa Nur Isnaini S.</p>
 <p>10018152</p>
 <p> <a href="#"><i class="icon-big icon-facebook-sign"></i> Facebook </a>
 <a href="#"><i class="icon-big icon-twitter-sign"></i> Twitter </a> </p>

 </div>
 <div class="span4 marg5">
 <p>Merlinda Wibowo</p>
 <p>10018160</p>
 <p> <a href="#"><i class="icon-big icon-facebook-sign"></i> Facebook </a>
 <a href="#"><i class="icon-big icon-twitter-sign"></i> Twitter </a> </p>


 </div>
 </div>
 </div>

 <div class="item">
 <div class="row box center">
 <div class="span4 marg5">
 <p>Dimas Ragil T.</p>
 <p>10018203</p>
 <p> <a href="#"><i class="icon-big icon-facebook-sign"></i> Facebook </a>
 <a href="#"><i class="icon-big icon-twitter-sign"></i> Twitter </a> </p>
 </div>
 <div class="span4 marg5">
 <p>Rio Herdian P.</p>
 <p>10018213</p>
 <p> <a href="#"><i class="icon-big icon-facebook-sign"></i> Facebook </a>
 <a href="#"><i class="icon-big icon-twitter-sign"></i> Twitter </a> </p>
 </div>
 <div class="span4 marg5">
 <p>TP Pemrograman Web Dinamis</p>


 </div>
 </div>
 </div>



 </div>
 <a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a>
 <a class="right carousel-control" href="#myCarousel" data-slide="next"> &rsaquo;</a>
 </div>




 </div>



 </div>

 <div class="row">
 <div class="span12">
 <p align="center">Copyright &copy;2012 TP PWD </p>
 </div>

 </div>

 </div>

<!-- Le javascript
 ================================================== -->
 <!-- Placed at the end of the document so the pages load faster -->
 <script src="js/jquery.js"></script>
 <script src="js/bootstrap.js"></script>
 <script src="js/script.js"></script>

</body>
</html>

 

belum sampai disitu..kita harus membuat sebuah proses eksekusi pemesanan

silahkan buat lagi file kerja dengan nama *pemesanan (*tidak direkomendasikan untuk kesekian kalinua -_- )
copas code berikut


<?php
 include "koneksi.php";

$query=mysql_query("insert into pemesanan(`kode_plg`, `jumlah`) values ('$_POST[kode_plg]','$_POST[jumlah]');");

 if($query):
 echo "<script>alert('Pemesanan Anda Berhasil');</script>";
 echo "<script>location.href='index.php';</script>";
 else :
 echo "<script>alert('Pemesanan Gagal Silahkan Coba lagi');</script>";
 echo "<script>location.href='pesan.php';</script>";
 endif;
?>

 

code diatas berfungsi untuk mengeksekusi hasil inputan form pemesanan yang nantinya akan tersimpan didalam databases yang telah kita buat 🙂

tampilannya seperti ini ^_^

 

Advertisements

2 thoughts on “Pemograman Web Dinamis (Catalog) PHP dan MySql #2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s