Wednesday, March 7, 2018

Product Inventory System in PHP and MySQLi

A very simple product inventory system that I wrote using PHP and MySQLi that can be used the daily product transaction of a business.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output


Program Listing


db.php

<?php
     define('_HOST_NAME','localhost');
     define('_DATABASE_NAME','inventory');
     define('_DATABASE_USER_NAME','root');
     define('_DATABASE_PASSWORD','');
     $MySQLiconn = new MySQLi(_HOST_NAME,_DATABASE_USER_NAME,_DATABASE_PASSWORD,_DATABASE_NAME);
 
if($MySQLiconn->connect_errno)
{
die("ERROR : -> ".$MySQLiconn->connect_error);
}
 
products.sql

-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Mar 07, 2018 at 02:31 AM
-- Server version: 10.1.16-MariaDB
-- PHP Version: 5.6.24

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `inventory`
--

-- --------------------------------------------------------

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` int(11) NOT NULL,
  `product` varchar(200) NOT NULL,
  `beginning` int(10) NOT NULL,
  `end` int(10) NOT NULL,
  `balance` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`id`, `product`, `beginning`, `end`, `balance`) VALUES
(4, 'Chicken Siomai', 50, 25, 25),
(5, 'Sharks Fin Siomai', 100, 25, 75),
(6, 'Coke', 250, 20, 230);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

crud.php

<?php

include_once 'db.php';

/* code for data insert */
if(isset($_POST['save']))
{

     $product = $MySQLiconn->real_escape_string($_POST['product']);
     $begin = $MySQLiconn->real_escape_string($_POST['beginning']);
$end = $MySQLiconn->real_escape_string($_POST['end']);
     $balance = $MySQLiconn->real_escape_string($_POST['balance']);
$SQL = $MySQLiconn->query("INSERT INTO products(product,beginning,end,balance) 
                     VALUES('$product','$begin','$end','$balance')");
 
if(!$SQL)
{
echo $MySQLiconn->error;
}
/* code for data insert */


/* code for data delete */
if(isset($_GET['remove']))
{
$SQL = $MySQLiconn->query("DELETE FROM products WHERE id=".$_GET['remove']);
header("Location: index.php");
}
/* code for data delete */



/* code for data update */
if(isset($_GET['editme']))
{
$SQL = $MySQLiconn->query("SELECT * FROM products WHERE id=".$_GET['editme']);
$getROW = $SQL->fetch_array();
}

if(isset($_POST['update']))
{
$SQL = $MySQLiconn->query("UPDATE products SET product='".$_POST['product']."',beginning='".$_POST['beginning']."',end='".$_POST['end']."',balance='".$_POST['balance']. "'WHERE id=".$_GET['editme']);
header("Location: index.php");
/* code for data update */
}
?>


index.php

<?php
include_once 'crud.php';
?>
<!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>Product Inventory System in PHP and MySQL</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<style>
body {
background-color:lightgreen;
font-family:arial;
size:16px;
}

p {
font-weight:bold;
font-family:arial;
size:16px;
}
}

</style>

<body>
 <center>

<br />
<h1>Product Inventory System in PHP and MySQL</h1>
<p> Created By Mr. Jake R. Pomperada, MAED-IT </p>
<br />
<div id="form">
<form method="post">
<table width="100%" border="1" cellpadding="15">
<tr>
<td><input type="text"  name="product" placeholder="Product Name" value="<?php if(isset($_GET['editme'])) echo $getROW['product'];  ?>" /></td>
</tr>
<tr>
<td><input type="number" name="beginning" placeholder="Beginning Quantity" value="<?php if(isset($_GET['editme'])) echo $getROW['beginning'];  ?>" /></td>
</tr>
<tr>
<td><input type="number" name="end" placeholder="End Quantity" value="<?php if(isset($_GET['editme'])) echo $getROW['end'];  ?>" /></td>
</tr>
<td><input type="number" name="balance" placeholder="Balance Quantity" value="<?php if(isset($_GET['editme'])) echo $getROW['balance'];  ?>" /></td>
</tr>
<tr>
<td>
<?php
if(isset($_GET['editme']))
{
?>
<button type="submit" name="update">UPDATE</button>
<?php
}
else
{
?>
<button type="submit" name="save">SAVE</button>
<?php
}
?>
</td>
</tr>
</table>
</form>

<br /><br />

<table width="100%" border="1" cellpadding="15" align="center">
<?php
$id=1;
$res = $MySQLiconn->query("SELECT * FROM products");
while($row=$res->fetch_array())
{

?>
    <tr>
    <td><?php echo $id ?></td>
    <td><?php echo $row['product']; ?></td>
    <td><?php echo $row['beginning']; ?></td>
<td><?php echo $row['end']; ?></td>
    <td><?php echo $row['balance']; ?></td>
    <td><a href="?editme=<?php echo $row['id']; ?>" onclick="return confirm('Are you sure to modify this record?'); " >Modify</a></td>
    <td><a href="?remove=<?php echo $row['id']; ?>" onclick="return confirm('Are you sure to remove this record?'); " >Remove</a></td>
    </tr>
    <?php
$id+=1;
}
?>
</table>
</div>
</center>
</body>
</html>

style.css

@charset "utf-8";
/* CSS Document */



#form
{
width:500px;
font-family:arial;
size:16px;
margin:0px auto;
text-align:center;
}
#form form input
{
width:100%;
height:55px;
}
form button
{
width:50%;
height:35px;
}
table,td
{
border:solid #e9e9e9 10px;
}







No comments:

Post a Comment