Website Toko Online






Berikut adalah daftar source code aplikasi shoppingcart online  =
Index.php =
<?php
    require_once("conn.php");
    if (!isset($_SESSION)) {
        session_start();
    }
?>
 <body background="images-11.jpg"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Toko Andin</title>
<style>
    h1, h2, h3, p {
        margin-top:0px;
        margin-bottom:10px;
    }
</style>
</head>

<body>

<h1>Toko Andin</h1>
<h2>List Produk</h2>
<hr />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr valign="top">
    <td width="55%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <?php
    mysql_select_db($database_conn, $conn);
    $query = mysql_query ("select * from barang");
    while ($rs = mysql_fetch_array ($query)) {
       
    ?>
      <tr>
        <td width="160" valign="top"><img src="<?php echo $rs['gambar']; ?>" alt="" style="width:140px; margin-right:20px; margin-bottom:20px;" /></td>
        <td valign="top"><h3><?php echo $rs['nama']; ?></h3>
          <p><?php echo $rs['deskripsi']; ?></p>
          <p>Harga : <?php echo number_format($rs['harga']); ?> - <a href="cart.php?act=add&amp;barang_id=<?php echo $rs['id']; ?>&amp;ref=index.php">Beli</a></p></td>
        </tr>
      <?php
    }
    ?>
    </table></td>
    <td>&nbsp;</td>
    <td width="40%"><p>Keranjang Anda</p>
      <hr />
      <?php require("cart_view.php"); ?></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>

conn.php =
<?php
$hostname_conn = "localhost";
$database_conn = "shoppingcart";
$username_conn = "root";
$password_conn = "";
$conn = mysql_connect($hostname_conn, $username_conn, $password_conn) or die(mysql_error());
?>

cart.php =
<?php
    require_once("conn.php");
    if (!isset($_SESSION)) {
        session_start();
    }
 
    if (isset($_GET['act']) && isset($_GET['ref'])) {
        $act = $_GET['act'];
        $ref = $_GET['ref'];
         
        if ($act == "add") {
            if (isset($_GET['barang_id'])) {
                $barang_id = $_GET['barang_id'];
                if (isset($_SESSION['items'][$barang_id])) {
                    $_SESSION['items'][$barang_id] += 1;
                } else {
                    $_SESSION['items'][$barang_id] = 1;
                }
            }
        } elseif ($act == "plus") {
            if (isset($_GET['barang_id'])) {
                $barang_id = $_GET['barang_id'];
                if (isset($_SESSION['items'][$barang_id])) {
                    $_SESSION['items'][$barang_id] += 1;
                }
            }
        } elseif ($act == "min") {
            if (isset($_GET['barang_id'])) {
                $barang_id = $_GET['barang_id'];
                if (isset($_SESSION['items'][$barang_id])) {
                    $_SESSION['items'][$barang_id] -= 1;
                }
            }
        } elseif ($act == "del") {
            if (isset($_GET['barang_id'])) {
                $barang_id = $_GET['barang_id'];
                if (isset($_SESSION['items'][$barang_id])) {
                    unset($_SESSION['items'][$barang_id]);
                }
            }
        } elseif ($act == "clear") {
            if (isset($_SESSION['items'])) {
                foreach ($_SESSION['items'] as $key => $val) {
                    unset($_SESSION['items'][$key]);
                }
                unset($_SESSION['items']);
            }
        }
     
        header ("location:" . $ref);
    }
 
?>

cart_view.php =
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="viewer">
  <tr>
    <th align="left" scope="col">Kode Barang</th>
    <th align="left" scope="col">Nama Barang</th>
    <th align="right" scope="col">Harga</th>
    <th align="right" scope="col">Qty</th>
    <th align="right" scope="col">Jumlah Harga</th>
    <th align="right" scope="col">Aksi</th>
  </tr>
  <?php
  $total = 0;
  if (isset($_SESSION['items'])) {
        foreach ($_SESSION['items'] as $key => $val){
            $query = mysql_query ("select barang.id, barang.nama, barang.harga from barang where barang.id = '$key'");
            $rs = mysql_fetch_array ($query);
         
            $jumlah_harga = $rs['harga'] * $val;
            $total += $jumlah_harga;
  ?>
  <tr>
    <td><?php echo $rs['id']; ?></td>
    <td><?php echo $rs['nama']; ?></td>
    <td align="right"><?php echo number_format($rs['harga']); ?></td>
    <td align="right"><?php echo number_format($val); ?></td>
    <td align="right"><?php echo number_format($jumlah_harga); ?></td>
    <td align="right"><a href="cart.php?act=plus&amp;barang_id=<?php echo $key; ?>&amp;ref=index.php">+</a> | <a href="cart.php?act=min&amp;barang_id=<?php echo $key; ?>&amp;ref=index.php">-</a> | <a href="cart.php?act=del&amp;barang_id=<?php echo $key; ?>&amp;ref=index.php">Hapus</a></td>
  </tr>
  <?php
            mysql_free_result($query);
        }
  }
  ?>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right"><?php echo number_format($total); ?></td>
    <td align="right"><a href="cart.php?act=clear&amp;ref=index.php">Clear</a></td>
  </tr>
</table>

TAMPILAN DATABASE SHOPPINGCART


TAMPILAN TABEL BARANG



TAMPILAN TABEL ITEM PENJUALAN



TAMPILAN TABEL PELANGGAN



TAMPILAN TABEL PENJUALAN



NAMA : Patria Juniarti Andini
KELAS : TI-VIDK
NIM : A2.1400080
0 Komentar untuk "Website Toko Online"

Silakan tinggalkan komentar anda. DILARANG KERAS menyimpan link blog/web pada komentar dengan tujuan backlink, Spam.

 
Copyright © 2014 Tutorial Kampus - All Rights Reserved
Template By. Catatan Info