PHP MySQL Ecommerce Web Design Part 6
Postingan saya kali ini adalah membuat halaman clothingStock_list.php beserta file-file yang berhubungan dengannya
1. Buat file .PHP dengan nama clothingStock_list.php di dalam folder admin
Buka Notepad++, pilih File, klik Open, cari file clothingStock_list.php di dalam folder admin. Isikan sama seperti script warna biru di bawah lalu jangan lupa di-save :<?php include_once("check_admin.php"); ?>
<?php
// Error Reporting
error_reporting(E_ALL);
ini_set('display_errors','1');
?>
<?php
// Delete item question to admin and delete product if choosen
if(isset($_GET['deleteid'])){
echo 'Do you really want to delete product with ID of'
.$_GET['deleteid'].
'?<a href="clothingStock_list.php?yesdelete='.$_GET['deleteid'].'">
Yes</a> | <a href="clothingStock_list.php">No</a>';
exit();
}
if(isset($_GET['yesdelete'])){
// remove item from system and delete its picture
// delete from database
$id_to_delete=$_GET['yesdelete'];
$sql=mysql_query("DELETE FROM clothingStock
WHERE stock_id='$id_to_delete' LIMIT 1") or die (mysql_error());
// unlink the image from server
if(file_exists($pictodelete)){
unlink($pictodelete);
}
// and reload page
header("location:clothingStock_list.php");
exit();
}
?>
<?php
////////////////// ORDER BY ///////////////////////////
include_once("clothingSL_orderby.php");
////////////////////////END of ORDER BY ///////////////
// This block grabs the whole list for viewing
$stock_list="";
if(isset($orderby)){
$sqlStock=mysql_query("SELECT clothingStock.stock_id,
clothingStock.product_name, clothingStock.color,
clothingStock.size, clothingStock.stock_amount,
clothingStock.date_added, clothingStock.store_name, clothing.id
FROM clothingStock INNER JOIN clothing
ON clothingStock.product_name=clothing.product_name $orderby_query ");
}
$stockCount=mysql_num_rows($sqlStock); // count the output amount
if($stockCount>0){
while($row=mysql_fetch_array($sqlStock)){
$id=$row["id"];
$stock_id=$row["stock_id"];
$product_name=$row["product_name"];
$store_name=$row["store_name"];
$color=$row["color"];
$size=$row["size"];
$stock_amount=$row["stock_amount"];
$date_added=strftime("%d-%m-%Y", strtotime($row["date_added"]));
$stock_list.='<div id="stocklist2">';
$stock_list.='<div id="stocklist_A1">'.$stock_id.'
</br>
<img class="goyang100" src="../clothing_stock_images1/
' . $stock_id . '.jpg" width="50" height="50" alt="x"
class="one-edge-shadow" style="border-color:blue;
border-style:solid; border-width:0px" />
</div>';
$stock_list.='<div id="stocklist_B1">'.$product_name.'
</div>';
$stock_list.='<div id="stocklist_C1">'.$store_name.'
</div>';
$stock_list.='<div id="stocklist_D1">'.$color.'</br> '.$size.'
</div>';
$stock_list.='<div id="stocklist_E1">'.$stock_amount.'
</div>';
$stock_list.='<div id="stocklist_F1">'.$date_added.'
</div>';
$stock_list.="<div id='stocklist_G1'>
<a href='stock_clothing.php?pid=".$id."'>
<button>Stock</button></a>
<a href='clothingStock_list.php?deleteid=".$stock_id."'>
<button>delete</button></a>
</div>";
$stock_list.='</div>';
}
}else{
$stock_list="You have no stock listed";
} // closing if ...
?>
<!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>Clothing Stock List</title>
<!---------------------- LINK -------------------------->
<?php include_once("template_links_head2.php"); ?>
<!---------------------- END of LINK -------------------------->
</head>
<body>
<div id="wrapper">
<div id="contentStock" style="font-size:14px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif">
<div id="pagNumTopOL" align="left" style="font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif; font-size:14px">
<?php include_once("clothingSL_orderbyForm.php"); ?>
</div> <!--- END pagNum --->
<br />
<br />
<center><h2>CLOTHING STOCK LIST</h2></center>
<a href="clothing_list.php" style="text-decoration:none">
<input name="home" type="button" value="<- Inventory List"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif" />
</a>
<a href="index.php" style="text-decoration:none">
<input name="home" type="button" value="<- Home"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif" />
</a>
<br />
<br />
<div id="stocklist" style="font-size:13px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif">
<div id="stocklist_A">Image</div>
<div id="stocklist_B">Prod Name</div>
<div id="stocklist_C">Supplier</div>
<div id="stocklist_D">Color/Size</div>
<div id="stocklist_E">Stock</div>
<div id="stocklist_F">Date Added</div>
<div id="stocklist_G">Delete</div>
</div>
<div id="stocklistWraper"><?php echo $stock_list; ?></div>
</div><!--- END contentStock --->
</div><!--- END Wrapper --->
</body>
</html>
2. Buat file .PHP dengan nama clothingSL_orderby.php di dalam folder admin
Buka Notepad++, pilih File, klik Open, cari file clothingSL_orderby.php di dalam folder admin. Isikan sama seperti script warna biru di bawah lalu jangan lupa di-save :
<?php
$selected = array();
if (isset($_GET["orderby"])) // pemakaian isset penting!!!
$orderby =($_GET["orderby"]);
if(!isset($orderby)){ $orderby = 'id_asc'; }
if(isset($orderby)){
$selected[$orderby] = 'selected';}
if($orderby == 'id_asc'){
$orderby_query = "order by stock_id asc"; }
else if($orderby == 'product_name_asc') {
$orderby_query = "order by product_name asc";}
else if($orderby == 'date_desc') {
$orderby_query = "order by date_added desc";}
else if($orderby == '10date_desc') {
$orderby_query = "order by date_added desc limit 10";}
else if($orderby == '30date_desc') {
$orderby_query = "order by date_added desc limit 30";}
else if($orderby == ''){
$orderby_query = "";}
else { unset($orderby); }
?>
3. Buat file .PHP dengan nama clothingSL_orderbyForm.php di dalam folder admin
Buka Notepad++, pilih File, klik Open, cari file clothingSL_orderbyForm.php di dalam folder admin. Isikan sama seperti script warna biru di bawah lalu jangan lupa di-save :
<form method='get' style="display: inline;" name='orderby_form'>
<select name='orderby' onChange="orderby_form.submit();"
style="font-size:15px; width: 130px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif">
<option value='id_asc'
<?php if(isset($_GET['orderby'])){
$selected[$orderby]=isset($selected[$orderby]);
print $selected[$orderby]; }
?>>ID</option>
<option value='product_name_asc'
<?php if(isset($_GET['orderby'])){
$selected[$orderby]=isset($selected[$orderby]);
print $selected[$orderby]; }
?>>Product Name</option>
<option value='date_desc'
<?php if(isset($_GET['orderby'])){
$selected[$orderby]=isset($selected[$orderby]);
print $selected[$orderby];}
?>>Date Added</option>
<option value='10date_desc'
<?php if(isset($_GET['orderby'])){
$selected[$orderby]=isset($selected[$orderby]);
print $selected[$orderby];}
?>>10 Hari Terakhir</option>
<option value='30date_desc'
<?php if(isset($_GET['orderby'])){
$selected[$orderby]=isset($selected[$orderby]);
print $selected[$orderby]; }
?>>30 Hari Terakhir</option>
<option value=''
<?php if(isset($_GET['orderby'])){
$selected[$orderby]=isset($selected[$orderby]);
print $selected[$orderby]; }
?>>Order by</option>
</select>
</form>
4. Buat file .PHP dengan nama stock_clothing.php di dalam folder admin
Buka Notepad++, pilih File, klik Open, cari file stock_clothing.php di dalam folder admin. Isikan sama seperti script warna biru di bawah lalu jangan lupa di-save :
<?php include_once("check_admin.php"); ?>
<?php
// Error Reporting
error_reporting(E_ALL);
ini_set('display_errors','1');
?>
<?php
// Gather this products full information for inserting automatically
// into the edit form which located below on this page
if(isset($_GET['pid'])){
$targetID=$_GET['pid'];
$sql=mysql_query("SELECT*FROM clothing WHERE id='$targetID' LIMIT 1");
$productCount=mysql_num_rows($sql); // count the output amount
if($productCount>0){
while($row=mysql_fetch_array($sql)){
$product_name=$row["product_name"];
$product_price=$row["product_price"];
$product_priceF=number_format($product_price,0,',','.');
}
}else{
$product_list="The product is not listed!";
exit();
}
}
?>
<?php
// Parse the form data and add inventory item to the system
if(isset($_POST['addStock'])){
$pid=mysql_real_escape_string($_POST['thisID']);
$sql=mysql_query("SELECT*FROM clothing WHERE id='$pid'");
while($row=mysql_fetch_array($sql)){
$product_name=$row["product_name"];
$product_price=$row["product_price"];
}
$store_name=mysql_real_escape_string($_POST['store_name']);
$phone=mysql_real_escape_string($_POST['phone']);
$store_address=mysql_real_escape_string($_POST['store_address']);
$city=mysql_real_escape_string($_POST['city']);
$color=mysql_real_escape_string($_POST['color']);
$size=mysql_real_escape_string($_POST['size']);
$stock_amount=mysql_real_escape_string($_POST['stock_amount']);
$purchase_price=mysql_real_escape_string($_POST['purchase_price']);
// See if store name is an identical match to another name in the system
$sql=mysql_query("SELECT stock_id FROM clothingStock
WHERE product_name='$product_name' AND color='$color' AND size='$size' LIMIT 1");
$productMatch=mysql_num_rows($sql); // Count the output amount
if($productMatch > 0){
while($row=mysql_fetch_array($sql)) {
$stock_idS=$row["stock_id"];
$updateQuery = mysql_query ("UPDATE clothingStock
SET stock_amount = stock_amount + '$stock_amount'
WHERE product_name='$product_name' AND color='$color' AND size='$size' ")
or die (mysql_error());
}
}else{
// masukkan data-data terlebih dahulu ke clothingStock table,
// agar mysql_insert_id() bisa bekerja
$sql=mysql_query("INSERT INTO clothingStock
(product_name, store_name, color, size, stock_amount, date_added)
VALUES('$product_name', '$store_name', '$color', '$size', '$stock_amount', now())")
or die (mysql_error());
$pic_id=mysql_insert_id();
//Place image in the folder
$newname="$pic_id.jpg";
// Make sure that the inventory_images folder in the server has Write permission
move_uploaded_file($_FILES['img1']['tmp_name'],"../clothing_stock_images1/$newname");
move_uploaded_file($_FILES['img2']['tmp_name'],"../clothing_stock_images2/$newname");
move_uploaded_file($_FILES['img3']['tmp_name'],"../clothing_stock_images3/$newname");
} // closing if ...
include_once("stock_clothing_insertInto.php");
header("location:clothingStock_list.php");
exit();
}
?>
<?php
// ----------- dropdown city from shipping table -------//
$shipping_cities = mysql_query("SELECT DISTINCT CITY
FROM shipping ORDER BY id ASC");
$city = array();
while($row = mysql_fetch_row($shipping_cities)){
$city[] = $row[0];
}
// ----------- dropdown brand from brand table ---------//
$brand_list = mysql_query("SELECT DISTINCT brand
FROM brand ORDER BY brand ASC");
$brand = array();
while($row = mysql_fetch_row($brand_list)){
$brand[] = $row[0];
}
// ---------- dropdown brand from brand table ---------//
$listed_color = mysql_query("SELECT DISTINCT color
FROM color ORDER BY color ASC");
$color = array();
while($row = mysql_fetch_row($listed_color)){
$color[] = $row[0];
}
?>
<!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>Stock Clothing</title>
<!---------------------- LINK -------------------------->
<?php include_once("template_links_head2.php"); ?>
<!---------------------- END of LINK -------------------------->
</head>
<body>
<div id="wrapper">
<div id="productStock" class="one-edge-shadow">
<h2>ADD NEW STOCK</h2>
<img class="one-edge-shadow"
src="../clothing_images1/<?php echo $targetID; ?>.jpg"
width="120" height="120" alt="img4" style="border-color:#D6D6F3;
border-style:solid; border-width:2px" />
<br/>
<div>
<br/>
<form id="prodStock" name="prodStock" enctype="multipart/form-data"
method="post" action="stock_clothing.php">
Product Name:
<br />
<input name="product_name" type="text" id="product_name"
disabled="disabled" size="35" value="<?php echo $product_name ?>"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif" />
<br />
Product Price:
<br />
Rp.
<input name="product_price" type="text" id="product_price"
disabled="disabled" size="17" value="<?php echo $product_price ?>"
style="font-size:15px; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif" />
<br />
Color:
<br />
<?php // dropdown color retrieved from database
if(count($color) <= 0){
echo 'No results have been found.';
} else {
echo '<select name="color" id="color" style="font-size:15px; width: 180px;
font-family:Trebuchet MS, Arial, Helvetica, sans-serif">';
foreach($color as $color)
echo "<option style='font-size:15px; font-family:Trebuchet MS,
Arial, Helvetica, sans-serif'>$color</option>";
echo '</select>';
}
?>
<br />
Size:
<br />
<select name="size" id="size" style="font-size:15px; width: 170px;
font-family:'Trebuchet MS', Arial, Helvetica, sans-serif">
<option value="0">Please Select</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select>
<br />
Supplier/Toko:
<br />
<input name="store_name" type="text" id="store_name" size="35"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif" />
<br />
Telepon/HP:
<br />
<input name="phone" type="text" id="phone" size="35"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif" />
<br />
Alamat Supplier/Toko:
<br />
<textarea name="store_address" id="store_address" cols="23" rows="5"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif"></textarea>
<br />
City:
<br />
<?php // dropdown city retrieved from data base
if(count($city) <= 0){
echo 'No results have been found.';
} else {
echo '<select name="city" id="city" style="font-size:15px;
font-family:Trebuchet MS, Arial, Helvetica, sans-serif">';
foreach($city as $city)
echo "<option style='font-size:15px; font-family:Trebuchet MS, Arial,
Helvetica, sans-serif'>$city</option>";
echo '</select>';
}
?>
<br />
Stock Amount:
<br />
<input name="stock_amount" type="text" id="stock_amount" size="19"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif" />
<br />
Purchase Price:
<br />
Rp.
<input name="purchase_price" type="text" id="purchase_price" size="17"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif" />
<br />
Stock Image 1:
<span style="font-size:13px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif; color:blue"> (.jpg)</span>
<input type="file" name="img1" id="img1" style="font-size:15px;
font-family:'Trebuchet MS', Arial, Helvetica, sans-serif"/>
<br />
Stock Image 2:
<span style="font-size:13px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif; color:blue"> (.jpg)</span>
<input type="file" name="img2" id="img2" style="font-size:15px;
font-family:'Trebuchet MS', Arial, Helvetica, sans-serif"/>
<br />
Stock Image 3:
<span style="font-size:13px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif; color:blue"> (.jpg)</span>
<input type="file" name="img3" id="img3" style="font-size:15px;
font-family:'Trebuchet MS', Arial, Helvetica, sans-serif"/>
<br />
<br />
<input name="thisID" type="hidden" value="<?php echo $targetID ?>"/>
<input type="submit" name="addStock" id="button" value="Add New Stock Now"
style="font-size:15px; font-family:'Trebuchet MS',
Arial, Helvetica, sans-serif"
/>
</form>
<br />
<a href="clothingStock_list.php" style="text-decoration:none">
<input name="back" type="button" value="Back" style="font-size:15px;
font-family:'Trebuchet MS', Arial, Helvetica, sans-serif" /></a>
</div>
</div><!--- END productStock --->
</div><!--- END Wrapper --->
<?php include_once("../template_js_body.php"); ?>
</body>
</html>
5. Buat file .PHP dengan nama stock_clothing_insertInto.php di dalam folder admin
Buka Notepad++, pilih File, klik Open, cari file stock_clothing_insertInto.php di dalam folder admin. Isikan sama seperti script warna biru di bawah lalu jangan lupa di-save :
<?php
// See if store name is an identical match to another name in the system
$sql=mysql_query("SELECT store_id FROM clothingStores
WHERE store_name='$store_name' LIMIT 1");
$productMatch=mysql_num_rows($sql); // Count the output amount
if($productMatch > 0){
}else{
// Add this product into clothingStores table
$sql=mysql_query("INSERT INTO clothingStores (store_name, phone,
address, city, date_added)
VALUES('$store_name', '$phone', '$store_address', '$city', now())")
or die (mysql_error());
}
// Add this product into clothingPurchase table
$sql=mysql_query("INSERT INTO clothingPurchase (product_name, store_name,
product_price, purchase_price, stock_amount, date_added)
VALUES('$product_name', '$store_name', '$product_price',
'$purchase_price', $stock_amount, now())")
or die (mysql_error());
?>
6. Buka Notepad++, pilih File, klik Open, cari file style.php di dalam folder styleCSS. Isikan sama seperti script warna biru di bawah lalu jangan lupa di-save :
/*--------------- stock_list----------------- */
#contentStock {
-moz-border-radius: 8px 8px 8px 8px; /* for Firefox */
-webkit-border-radius: 8px 8px 8px 8px; /* for Webkit-Browsers */
border-radius: 8px 8px 8px 8px; /* regular */
opacity: 0.8;
margin-right: auto;
margin-left: auto;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
overflow: hidden;
width: 798px;
position: relative;
display: block;
padding: 30px;
border: 1px solid #CCC;
background-color: #FFF;
}
#stocklist {
width: 800px;
height: 35px;
margin: 0px;
float: left;
position: relative;
}
#stocklist_A {
padding: 2px;
float: left;
height: 30px;
width: 70px;
text-align: center;
margin: 0px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_B {
margin: 0px;
float: left;
height: 30px;
width: 200px;
text-align: center;
padding: 2px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_C {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 30px;
width: 100px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_D {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 30px;
width: 60px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_E {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 30px;
width: 100px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_F {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 30px;
width: 70px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_G {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 30px;
width: 160px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklistWraper {
width: 800px;
position: relative;
overflow: hidden;
padding-bottom: 10px;
}
#stocklist2 {
width: 800px;
height: 85px;
margin: 0px;
float: left;
position: relative;
}
#stocklist_A1 {
padding: 2px;
float: left;
height: 80px;
width: 70px;
text-align: center;
margin: 0px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_B1 {
margin: 0px;
float: left;
height: 80px;
width: 200px;
text-align: center;
padding: 2px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_C1 {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 80px;
width: 100px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_D1 {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 80px;
width: 60px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_E1 {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 80px;
width: 100px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_F1 {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 80px;
width: 70px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
#stocklist_G1 {
text-align: center;
margin: 0px;
padding: 2px;
float: left;
height: 80px;
width: 160px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #999;
background-color: #FFF;
}
/*--------------- product_stock----------------- */
#productStock {
-moz-border-radius: 10px; /* for Firefox */
-webkit-border-radius: 10px; /* for Webkit-Browsers */
border-radius: 10px; /* regular */
opacity: 0.8; /* Transparent Background 50% */
padding: 20px;
width: 480px;
margin-right: auto;
margin-left: auto;
background-color: #FFF;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
overflow: hidden;
position: relative;
}
7. Upload semua file ke web server
8. Buka dengan browser 192.168.88.111, klik admin di bagian footer, User Name: rian, Password: 654321, klik tombol Lihat Stock Clothing
Saya akan menambah stock produk dengan nama RK_00001. Pada baris RK_00001 klik tombol Stock
Product Name dan Product Price tidak bisa dirubah. Isi dengan produk baru lalu klik Add New Stock Now. Secara otomatis akan kembali ke halaman clothingStock_list.php. Jika ingin menambah lagi stock RK_00001, klik tombol Stock pada baris RK_00001.
Jika di-stock semua maka untuk produk RK_00001 saja akan terdiri dari 20 variasi
Comments
Post a Comment