Mobile Product Management on web
   
I.     
Objective
·        
Manage Product / Product’s detail 
-      
Insert new Product
-      
Product’s Detail 
-      
Delete Product
-      
List Product (select product)
·        
Manage Category
-       Add
new Category
-       Update
/ delete Category 
-       Select
Category
·        
Manage User Login
-       Add
new user 
-       Edit/delete
user
-       List
all user 
·        
Search Product 
II. Database Design
a. ER Diagram
b. Data Dictionary
tblproduct
tblproduct_detail
tblcategory
tbluser
III. Directory Structure
Main Folder is MSProductIn folder admin :
IV. Interface
Product's Detail Page :
Admin Login : 
V. Coding
1. config.php
<?php$dbhost='localhost';
$dbuser='root';
$dbpws='';
$conn=mysql_connect($dbhost,$dbuser,$dbpws);
if(! $conn ) { die('Could not connect: '
. mysql_error()); }
mysql_select_db('dbproduct');
?>
----------------------------------------------------------------
2. Login Coding
login.php<h1>Login Form</h1>
<table border=1 width=300>
<tr><td align="center">
<h2>Login To Your Account</h2>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<input placeholder='Username' type='text' name="txtUserid"><br><br>
<input placeholder='Password' type='text' name="txtUserpwd"><br><br>
<button name="btn">Login</button><br><br>
</form>
</td></tr>
</table>
-----------------------------------------------------------------
3. Logout Coding
logout.php<?php
session_start();
unset($_SESSION['isLogin']);
header('Location:login.php');
exit;
?>
-----------------------------------------------------------------
4. Admin / index.php
<a href="logout.php">Logout</a><?php
session_start();
if(!isset($_SESSION['isLogin'])){
header('Location:login.php');
exit;
}
?>
<html>
<body>
<center>
<table border=1 width=850 height=400>
<tr><td colspan="2">Admin Zoon
<br><a href="product/show.php">Manage Product</a>/
<a href="Category/select_cate.php">Manage Category</a>/
<a href="user/index.php">User Setting</a>
</td></tr>
<tr><td>Menu
<ul>
<li><a href="product/show.php">product list</a></li>
<li><a href="product/add_product.php">Add new Product</a></li>
<li><a href="category/add_cate.php">Add new Category</a></li>
<li><a href="category/select_cate.php">Category List</a></li>
<li><a href="user/index.php">User Setting</a></li>
</ul>
</td>
<td>Welcome to admin zoon
</td></tr>
<tr><td colspan="2">footer</td></tr>
</table>
</center>
</body>
</html>
-------------------------------------------------------------------
5. Folder Category : add_cate.php , delete_cate.php ,
edit_cate.php, select_cate.php
add_cate.php (add Category with the Form Validation)
<?phpif(isset($_POST['add']))
{
include_once('../../config.php');
$name=$_POST['txtcatename'];
$detail=$_POST['txtcatedetail'];
$sql="insert into tblcategory(cate_id,cate_name,cate_detail) values('','$name','$detail')";
$result=mysql_query($sql,$conn);
if(!$result){
echo"error".mysql_error();
}
else{echo"success";
include_once('select_cate.php');}
exit;
}
else{
?>
<html>
<head><title>add category</title>
<script language="javascript">
function validateFormOnSubmit(theForm) {
var reason = "";
reason += validateEmpty(theForm.txtcatename);
reason += validateEmpty(theForm.txtcatedetail);
if (reason != "") {
alert("Some fields need correction:\n" + reason);
return false;
}
return true;
}
function validateEmpty(fld) {
var error = "";
if (fld.value.length == 0) {
fld.style.background = 'pink';
error = "The required field has not been filled in.\n"
} else {
fld.style.background = 'White';
}
return error;
}
</script>
</head>
<body>
<center>
<table border=1 width=850 height=400>
<tr><td colspan="2">Admin Zoon
<br><a href="../product/show.php">Manage Product</a>/
<a href="select_cate.php">Manage Category</a>/
<a href="../user/index.php">User Setting</a>
</td></tr>
<tr><td><p align="top">Menu
<ul>
<li><a href="../product/show.php">product list</a></li>
<li><a href="../product/add_product.php">Add new Product</a></li>
<li><a href="add_cate.php">Add new Category</a></li>
<li><a href="select_cate.php">Category List</a></li>
<li><a href="..user/index.php">User Setting</a></li>
</ul>
</p>
</td>
<td>
<form method="post" action="<?php $_PHP_SELF ?>"
onsubmit="return validateFormOnSubmit(this)"
name="theForm">
<table border="0">
<tr><td>category name
<td><input type="text" name="txtcatename"></tr>
<tr><td>category Detail
<td><input type="text" name="txtcatedetail"></tr>
<tr><td><input type="submit" name="add" value="insert"></tr>
</table>
</form>
<?php
} ?>
</td></tr>
<tr><td colspan="2">footer</td></tr>
</table>
</center>
</body>
</html>
----------------------------------------------------------------------------------------
Select_cate.php (List all of Category from table Category)
<html>
<head></head>
<body>
<center>
<table border=1 width=850 height=400>
<tr><td colspan="2">Admin Zoon
<br><a href="../product/show.php">Manage Product</a>/
  <a href="select_cate.php">Manage Category</a>/
  <a href="../user/index.php">User Setting</a>
</td></tr>
<tr><td><p align="top">Menu
  <ul>
    <li><a href="../product/show.php">product list</a></li>
    <li><a href="../product/add_product.php">Add new Product</a></li>
    <li><a href="add_cate.php">Add new Category</a></li>
    <li><a href="select_cate.php">Category List</a></li>
    <li><a href="..user/index.php">User Setting</a></li>
  </ul>
</p>
</td>
<td>
<?php
include_once('../../config.php');
$sql="select * from tblcategory";
$check=mysql_query($sql,$conn);
if( !$check ){ die('Could not select: ' 
   . mysql_error()); }
echo"<table border=1>";
echo"<tr><th>category ID<th>Category Name<th>Detail</tr>";
while($row=mysql_fetch_array($check,MYSQL_ASSOC)){
 $id=$row['cate_id'];
 $name=$row['cate_name'];
 $detail=$row['cate_detail'];
echo"<tr><td>$id<td>$name<td>$detail<td>";
?>
 <a href=edit_cate.php?varID=<?php echo $id ?>>Edit</a><td>
 <a href=delete_cate.php?varID=<?php echo $id ?>>Delete</a>
 </tr>
<?php
}
echo"</table>";
echo"<a href='add_cate.php'>Add new Category</a>";
mysql_close($conn);
?>
  </td></tr>
<tr><td colspan="2">footer</td></tr>
</table>
</center>
</body>
</html>
----------------------------------------------------------------------------------------
delete_cate.php (this file you can delete category from table category by ID)
<?php
include_once('../../config.php');
$id1=$_GET['varID'];
$sql="delete from tblcategory where cate_id='$id1'";
$result=mysql_query($sql,$conn);
if(! $result ) { 
die('Could not delete data: ' . mysql_error()); 
} 
include_once('select_cate.php');
//mysql_close($conn);
?>
---------------------------------------------------------------------------------------
edit_cate.php
<?php
include_once('../../config.php');
$id1=$_GET['varID'];
$query="select * from tblcategory where cate_id='$id1'";
$result=mysql_query($query,$conn);
while($row=mysql_fetch_assoc($result)){
 $id=$row['cate_id'];
 $title=$row['cate_name'];
 $dec=$row['cate_detail'];
}
echo $title ;
?>
<html>
<head><title>update category</title>
<?php
if(isset($_POST['update'])) 
{ 
include_once('../../config.php');
$name=$_POST['txtcatename'];
$detail=$_POST['txtcatedetail'];
$sql="UPDATE tblcategory
  SET cate_name='$name',cate_detail='$detail'
  WHERE cate_id='$id1'";
$result1=mysql_query($sql,$conn);
//mysql_select_db('dbproduct');
if(!$result1){
echo"error".mysql_error();
}
echo"success update";
include_once('select_cate.php');
//mysql_close($conn);
}
else{
?>
<body>
<center>
<table border=1 width=850 height=400>
<tr><td colspan="2">Admin Zoon
<br><a href="../product/show.php">Manage Product</a>/
  <a href="select_cate.php">Manage Category</a>/
  <a href="../user/index.php">User Setting</a>
</td></tr>
<tr><td><p align="top">Menu
  <ul>
    <li><a href="../product/show.php">product list</a></li>
    <li><a href="../product/add_product.php">Add new Product</a></li>
    <li><a href="add_cate.php">Add new Category</a></li>
    <li><a href="select_cate.php">Category List</a></li>
    <li><a href="..user/index.php">User Setting</a></li>
  </ul>
</p>
</td>
<td>
<form method="post" action="<?php $_PHP_SELF ?>">
<table border="0">
<tr><td>category name
 <td><input type="text" name="txtcatename" value="<?php echo $title; ?>"></tr>
<tr><td>category Detail
 <td><input type="text" name="txtcatedetail" value="<?php echo $dec; ?>"></tr>
<tr><td><input type="submit" name="update" value="update"></tr>
</table>
</form>
<?php 
} 
?>
  </td></tr>
<tr><td colspan="2">footer</td></tr>
</table>
</center>
</body>
</html>
----------------------------------------------------------------------------------------------------
6. Product's Folder : is Managing of all Product/Product Detail such as add new product , Edit product , delete product , add description of product (product_detail) and show the list of all product .
add_product.php
<?php
include_once"../../cate.php";
?>
<body>
<center>
<table border=1 width=850 height=400>
<tr><td colspan="2">Admin Zoon
<br><a href="show.php">Manage Product</a>/
  <a href="../Category/select_cate.php">Manage Category</a>/
  <a href="../user/index.php">User Setting</a>
</td></tr>
<tr><td><p align="top">Menu
  <ul>
    <li><a href="show.php">product list</a></li>
    <li><a href="add_product.php">Add new Product</a></li>
    <li><a href="../category/add_cate.php">Add new Category</a></li>
    <li><a href="../category/select_cate.php">Category List</a></li>
    <li><a href="../user/index.php">User Setting</a></li>
  </ul>
</p>
</td>
<td>
<form method="post" action="added_product.php" enctype="multipart/form-data">
<table border="0">
<tr><td>Product name</td>
 <td><input type="text" name="txtname"></td></tr>
<tr><td>category</td>
 <td><select name="cate">
  <?php echo $cateset;
   ?>
  </select>
   </td></tr>
<tr><td>Image</td>
 <td><input type="file" name="files"></td></tr>
<tr><td>Price</td>
 <td><input type="text" name="txtprice"></td></tr>
<tr><td><input type="submit" name="add" value="Add Product"></td>
 <td><input type="button" name="cancel" value="Cancel"></td></tr>
</table>
</form>
 </td></tr>
<tr><td colspan="2">footer</td></tr>
</table>
</center>
</body>
</html>
-----------------------------------------------------------------------------------------------
added_product.php
is the process of add product , mean that add_product is the interface of form using HTML coding and added_product is the php process data to database (tblproduct).
<?php
 $folder="../../product/upload/";
 $name = isset($_POST['txtname'])?$_POST['txtname']:'';
 $cate = isset($_POST['cate'])?$_POST['cate']:'';
 $img = isset($_FILES['files']['name'])?$_FILES['files']['name']:'';
 $price = isset($_POST['txtprice'])?$_POST['txtprice']:'';
include_once('../../config.php');
mysql_select_db('dbproduct');
move_uploaded_file($_FILES['files']['tmp_name'],$folder.$img);
$sql = "INSERT INTO tblproduct(
  pro_name,cat_name,pro_img,pro_price) 
  VALUES('$name','$cate','$img','$price')";
$retval = mysql_query($sql,$conn);
if(! $retval )
{
  die('Could not add data: ' . mysql_error());
}
echo "add data successfully\n<a href='show.php'>view list</a>";
 mysql_close($conn);
?>
-----------------------------------------------------------------------------------
show.php
is the List of all product have been insert to table tblproduct .In this file also include with the link to insert and update data of product_detail also. code :
include_once("../../config.php");
$sql="select * from tblproduct";
$result=mysql_query($sql,$conn);
$product_result="";
while($row=mysql_fetch_array($result)){
$id=$row['pro_id'];
$img=$row['pro_img'];
$name=$row['pro_name'];
$cate=$row['cat_name'];
$price=$row['pro_price'];
$product_result.="<fieldset><ul align='left'><li><a href='edit.php?ProID=$id'>".$name.
"</a></li><li>".$cate."</li><li>".$price.
"</li></ul>".
"<a href='edit.php?ProID=$id'><img src='../../product/upload/".$img."' width=100 align='right'></a>"
."</fieldset>";
}
?>
<html>
<body>
<center>
<table border=1 width=850 height=400>
<tr><td colspan="2">Admin Zoon
<br><a href="show.php">Manage Product</a>/
<a href="../Category/select_cate.php">Manage Category</a>/
<a href="../user/index.php">User Setting</a>
</td></tr>
<tr><td>asd<p align="top">Menu
<ul>
<li><a href="show.php">product list</a></li>
<li><a href="add_product.php">Add new Product</a></li>
<li><a href="../category/add_cate.php">Add new Category</a></li>
<li><a href="../category/select_cate.php">Category List</a></li>
<li><a href="../user/index.php">User Setting</a></li>
</ul>
</p>
</td>
<td><p><?php echo $product_result;?></p>
</td></tr>
<tr><td colspan="2">footer</td></tr>
</table>
</center>
</body>
</html>
-------------------------------------------------------------------------------------------------
add_pro_detail.php
For this file is the way of insert new data to tblproduct_detail from the form of list product , But if some data have already is automatic to update data in table . Code :
<?PHP
 $pro_id = isset($_REQUEST['ProID']) ? $_REQUEST['ProID'] : '';
 $general = isset($_POST['txtgeneral'])?$_POST['txtgeneral']:'';
    $size = isset($_POST['txtsize'])?$_POST['txtsize']:'';
 $display= isset($_POST['txtdisplay'])?$_POST['txtdisplay']:'';
 $sound = isset($_POST['txtsound'])?$_POST['txtsound']:'';
 $memory = isset($_POST['txtmemory'])?$_POST['txtmemory']:'';
 $data = isset($_POST['txtdata'])?$_POST['txtdata']:'';
 $camera= isset($_POST['txtcamera'])?$_POST['txtcamera']:'';
 $features = isset($_POST['txtfeature'])?$_POST['txtfeature']:'';
 $battery = isset($_POST['txtbattery'])?$_POST['txtbattery']:'';
 //Database Stuff
 include_once("../../config.php"); //connectio basis
 $query ="SELECT * FROM tblpro_detail WHERE pro_id = '$pro_id'";
 $testResult = mysql_query($query) or die('Error, query failed');
   if(mysql_fetch_array($testResult) == NULL){
    //insert...
 $query ="INSERT INTO tblpro_detail(pro_id,general,size,display,sound,memory,data,camera,features,Battery)
    VALUES ('$pro_id','$general','$size','$display','$sound',
         '$memory','$data','$camera','$features','$battery'
     )";
    $result = mysql_query($query) or die('Error, query failed insert');
 echo"insert data successful";
 }else{
    //update...
    $query = "UPDATE tblpro_detail SET pro_id='$pro_id', general='$general', size='$size',display='$display',sound='$sound',memory='$memory',data='$data',camera='$camera',features='$features',Battery='$battery'
        WHERE pro_id='$pro_id'";
        $result = mysql_query($query) or die('Error, query failed update '); 
  echo"update successful!";
}
?>
--------------------------------------------------------------------------------------------------------
delete.php
<?php
include_once('../../config.php');
$id1=$_GET['ProID'];
$sql="delete from tblproduct where pro_id='$id1'";
$result=mysql_query($sql,$conn);
if(! $result ) { 
die('Could not delete data: ' . mysql_error()); 
} 
echo"success delete";
?>
-------------------------------------------------------------------------------------------------------
edit.php
<?PHP
 $search_query = isset($_REQUEST['ProID']) ? $_REQUEST['ProID'] : '';
 /****Database Stuff *****/
 include_once("../../config.php"); //connectio basis
 //Display the record
 mysql_select_db('dbproduct');
 $query = "SELECT * FROM tblproduct WHERE pro_id='$search_query'";
 $result = mysql_query($query) or die('Error in query: $query' . mysql_error());
 //$row = mysql_fetch_assoc($result);
 //$result_display="";
 while($row=mysql_fetch_assoc($result)){
 $id=$row['pro_id'];
 $name=$row['pro_name'];
 $cate=$row['cat_name'];
 $img=$row['pro_img'];
 $price=$row['pro_price']; 
}
 /****select category*****/
 $query_cate = "SELECT * FROM tblcategory ORDER BY cate_name";
 $result_cate = mysql_query($query_cate) or die('Error in query: $query_cate' . mysql_error());
 $cateset = "";
 if (mysql_num_rows($result_cate) > 0){
  while ($row_cate = mysql_fetch_assoc($result_cate)){
   $cateset .= "<option value='" . $row_cate['cate_name'] . "' selected>" . $row_cate['cate_name'] . "</option>\n";
   }
 }
 $query_detail="SELECT * FROM tblpro_detail WHERE pro_id = '$search_query'";
 $result_detail = mysql_query($query_detail) or die('Error in query: $query_detail' . mysql_error());
 $row_detail = mysql_fetch_assoc($result_detail);
 //mysql_close($conn);
 /****End of Database Stuff *****/
?>
<html>
<head>
 <title>Edit Product</title></head>
<body>
<center>
<table border=1 width=850 height=400>
<tr><td colspan="2">Admin Zoon
<br><a href="show.php">Manage Product</a>/
  <a href="../Category/select_cate.php">Manage Category</a>/
  <a href="../user/index.php">User Setting</a>
</td></tr>
<tr><td><p align="top">Menu
  <ul>
    <li><a href="show.php">product list</a></li>
    <li><a href="add_product.php">Add new Product</a></li>
    <li><a href="../category/add_cate.php">Add new Category</a></li>
    <li><a href="../category/select_cate.php">Category List</a></li>
    <li><a href="../user/index.php">User Setting</a></li>
  </ul>
</p>
</td>
<td>
<?php
if(isset($_POST['delete'])){
include_once"delete.php";
}
else if(isset($_POST['update'])) 
{ 
include_once('../../config.php');
 $name1 = $_POST['txtname'];
 $cate1 = $_POST['cate'];
 $img1 = $_FILES['files']['name'];
 $price1 = $_POST['txtprice'];
 $folder="../../product/upload/";
move_uploaded_file($_FILES['files']['tmp_name'],$folder.$img1);
$sql="UPDATE tblproduct SET pro_name='$name1',cat_name='$cate1', pro_img='$img1',pro_price='$price1' 
  WHERE pro_id='$search_query'";
mysql_select_db('dbproduct');
$result1=mysql_query($sql,$conn);
if(!$result1){
echo"error".mysql_error();
}
include_once("add_pro_detail.php");
echo"success update";
//include_once('show.php');
}
else{
?>
<form method="post" action="<?php $_PHP_SELF ?>" enctype="multipart/form-data">
<table border="0">
<tr><td>Product name</td>
 <td><input type="text" name="txtname" value="<?php echo $name; ?>"></td></tr>
<tr><td>category</td>
 <td><input type="text" value="<?php echo $cate; ?>">
 <select name="cate">
 <?php 
  echo $cateset;?>
  </select>
   </td></tr>
<tr><td>Image</td>
 <td><input type="file" name="files"></td></tr>
<tr><td>Price</td>
 <td><input type="text" name="txtprice" value="<?php echo $price; ?>"></td></tr>
 <tr><td>general<td><input name="txtgeneral" type="text" size="50" value="<?PHP echo $row_detail['general'] ;?>"/></td></tr>
    <tr><td>size<td><input name="txtsize" type="text" size="50" value="<?PHP echo $row_detail['size'] ;?>"/></td></tr>
 <tr><td>Diplay<td><input name="txtdisplay" type="text" size="50" value="<?PHP echo $row_detail['display'] ;?>"/></td></tr>
 <tr><td>Sound<td><input name="txtsound" type="text" size="50" value="<?PHP echo $row_detail['sound'] ;?>"/></td>
     </tr>
    <tr><td>Memory<td><input type="text" name="txtmemory" size="50" value="<?PHP echo $row_detail['memory'] ;?>"></tr>
 <tr><td>Data<td><input name="txtdata" type="text" size="50" value="<?PHP echo $row_detail['data'] ;?>"/></td>
    <tr><td>Camera<td><input name="txtcamera" type="text" size="50" value="<?PHP echo $row_detail['camera'] ;?>"/></td>
 <tr><td>Features<td><input name="txtfeature" type="text" size="50" value="<?PHP echo $row_detail['features'] ;?>"/></td>
 <tr><td>Battery<td><input name="txtbattery" type="text" size="50" value="<?PHP echo $row_detail['Battery'] ;?>"/></td>
<tr><td><input type="submit" name="update" value="Edit"></td>
 <td><input type="submit" name="delete" value="delete"></td></tr>
</table>
</form>
<table align="left" border="1">
<tr><td><?php echo "<img src='../../product/upload/$img' width=100>"?></td></tr>
</table>
 </td></tr>
<tr><td colspan="2">footer</td></tr>
</table>
</center>
<?php
}
?>
</body>
</html>
Link to Part 2 
i











 
No comments:
Post a Comment