Monday, March 12, 2018

Table Creation and Insert of Record in SQLite

A very simple code to show you how to create a table and insert a record using SQLite. 

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

--
-- File generated with SQLiteStudio v3.1.1 on Mon Mar 12 13:54:08 2018
--
-- Text encoding used: System
--
PRAGMA foreign_keys = off;
BEGIN TRANSACTION;

-- Table: users
DROP TABLE IF EXISTS users;

CREATE TABLE users (
    user_id INTEGER    PRIMARY KEY,
    name    TEXT (100),
    age     INTEGER
);

INSERT INTO users (user_id, name, age) VALUES (1, 'jake', 39);
INSERT INTO users (user_id, name, age) VALUES (2, 'iya', 3);
INSERT INTO users (user_id, name, age) VALUES (3, 'allie', 46);
INSERT INTO users (user_id, name, age) VALUES (4, 'jacob', 4);

-- Index: 
DROP INDEX IF EXISTS "";

CREATE INDEX "" ON users (
    user_id
);


COMMIT TRANSACTION;
PRAGMA foreign_keys = on;




Friday, March 9, 2018

Sum of a Number in Java

I wrote this program to ask the user to give a series of numbers and then our program will sum up all the numbers using Java as my programming language.

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

sum.java


import java.util.Scanner;

class sum {

public static void main(String[] args) {
   Scanner input = new Scanner(System.in);

   System.out.print("Sum of a Number in Java");
   System.out.print("\n\n");
   System.out.print("Created By Mr. Jake R. Pomperada");
   System.out.print("\n\n");
  System.out.print("Give a Number : ");
  int n = input.nextInt();

 int number = n;
 int sum = 0;
 int num = number;

while (num > 0) {
        int lastDigit = num % 10;
        sum += lastDigit;
        num /= 10;
    }
    System.out.print("\n\n");
    System.out.println("Sum of digits is  "+sum +".");
    System.out.print("\n\n");
}

}




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;
}







Tuesday, March 6, 2018

Upload Picture in the Database Using PHP and MySQLi

In this article I would like to share with you a code that I wrote that enables you to upload a picture in your database using PHP and MySQLi. The code is very easy to understand and use. I hope you will find my work useful.

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


users.sql

-- phpMyAdmin SQL Dump
-- version 4.7.7
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Mar 06, 2018 at 12:57 PM
-- Server version: 10.1.30-MariaDB
-- PHP Version: 7.2.2

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
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: `login`
--

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(200) NOT NULL,
  `password` varchar(200) NOT NULL,
  `lastname` varchar(200) NOT NULL,
  `firstname` varchar(200) NOT NULL,
  `pix` varchar(500) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`, `lastname`, `firstname`, `pix`) VALUES
(1, 'jake', 'jake', 'POMPERADA', 'JAKE', '/login/images/jake.jpg'),
(2, '123', '123', 'POMPERADA', 'JACOB SAMUEL', '/login/images/jacob.jpg'),
(3, 'iya', 'iya', 'POMPERADA', 'JULIANNA RAE', '/login/images/iya.jpg'),
(4, 'allie', 'allie', 'POMPERADA', 'MA. JUNALLIE', '/login/images/allie.jpg'),
(5, 'bill', 'bill', 'GATES', 'WILLIAM', '/login/images/gates.jpg'),
(6, 'peter', 'peter', 'NORTON', 'PETER', '/login/images/norton.jpg'),
(15, 'alan', 'alan', 'TURING', 'ALAN', '/login/images/turing.jpg'),
(16, 'neil', 'neil', 'ARMSTRONG', 'NEIL ALDEN', '/login/images/armstrong.jpg'),
(18, 'kobe', 'kobe', 'BRYANT', 'KOBE', '/login/images/kobe.jpg'),
(21, 'larry', 'lary', 'BIRD', 'LARRY', '/login/images/bird.jpg'),
(22, 'linus', 'linus', 'LINUS', 'TORWALDS', '/login/images/linux.jpg'),
(23, 'james', 'james', 'GOSLING', 'JAMES', '/login/images/gosling.jpg');

--
-- Indexes for dumped tables
--

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

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=24;
COMMIT;

/*!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 */;

connect_to_database.php

<?php  
$localhost = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "login"; 
 
// create connection 
$connect = new mysqli($localhost, $username, $password, $dbname); 
 
// check connection 
if($connect->connect_error) {
    die("connection failed : " . $connect->connect_error);
} else {
    // echo "Successfully Connected";
}
  
?>


upload.php

<?php
error_reporting(0);
include 'connect_to_database.php'; 

$username = $_POST['username'];
$password = $_POST['password'];
$lastname = $_POST['lastname'];
$firstname =$_POST['firstname'];

$last = strtoupper($lastname);
$first = strtoupper($firstname);
  
  $msg = "";


  if (isset($_POST['upload']))  {

$image2 = $_FILES['image']['name'];
  $image = "/login/images/".$_FILES['image']['name'];


  // image file directory
  $target = "/xampp/htdocs/login/images/".basename($image2);

  $sql = "INSERT INTO users (username,password,lastname,firstname,pix) VALUES ('$username','$password','$last','$first','$image')";
  // execute query
  mysqli_query($connect, $sql);

  if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
 
header('Location: success.php');
  }else{
  $msg = "Failed to upload record and image.";
  }
  }
 
?>
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
<style type="text/css">
   #content{
    width: 50%;
    margin: 20px auto;
    border: 1px solid #cbcbcb;
   }
   form{
    width: 50%;
    margin: 20px auto;
   }
   form div{
    margin-top: 5px;
   }
   #img_div{
    width: 80%;
    padding: 5px;
    margin: 15px auto;
    border: 1px solid #cbcbcb;
   }
   #img_div:after{
    content: "";
    display: block;
    clear: both;
   }
   img{
    float: left;
    margin: 5px;
    width: 300px;
    height: 140px;
   }
   
body {
    background-color: lightgreen;
    font-family:arial;
    font-size:20px;
    }
input, button, select, option, textarea {
    font-size: 100%;
}

</style>
</head>
<body>
<div id="content">
    <form method="POST" action="upload.php" enctype="multipart/form-data">
  <input type="hidden" name="size" value="1000000">
<table cellspacing="0" cellpadding="0">
            <tr>
                <th>Username &nbsp;&nbsp;</th>
                <td><input type="text" name="username" placeholder="Name" required/> &nbsp;</td>
            </tr>   
            <tr>
                <th>Password</th>
                <td><input type="text" name="password" placeholder="Password" /></td>
            </tr>
<tr>
                <th>Lastname</th>
                <td><input type="text" name="lastname" placeholder="Lastname" /></td>
            </tr>
<tr>
                <th>Firstname</th>
                <td><input type="text" name="firstname" placeholder="Firstname" /></td>
            </tr>
</table>
  <div>
    <input type="file" name="image">
  </div>
    <div>
  <button type="submit" name="upload">POST</button>
  </div>
  </form>
  
  <?php
    echo $msg;
 ?>
</div>
</body>
</html>

success.php

<?php

$msg = "<h1> Record and Image uploaded successfully. </h1>";

echo $msg;

?>





Login With Name and Pictures in PHP and MySQLi

An application that I improve from my previous work that I added display of user name with pictures that I wrote in PHP and MySQLi. This is a simple login system that is database. I hope you find my work useful. 

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

connect_to_database.php

<?php  
$localhost = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "login"; 

// create connection 
$connect = new mysqli($localhost, $username, $password, $dbname); 

// check connection 
if($connect->connect_error) {
    die("connection failed : " . $connect->connect_error);
} else {
    // echo "Successfully Connected";
}
  
?>

home.php

<?php
include 'connect_to_database.php'; //connect the connection page

if(empty($_SESSION)) // if the session not yet started 
   session_start();

if(!isset($_SESSION['username'])) { //if not yet logged in
   header("Location: login.php");// send to login page
   exit;
?>
<html>
<body>
<style>

.avatar {
    vertical-align: middle;
    width: 252px;
    height: 220px;
    border-radius: 150%;
border:5px solid white;
    border-radius: 600px;
    -webkit-border-radius: 600px;
    -moz-border-radius: 600px;
}

body {
    background-color: lightgreen;
    font-family:arial;
    font-size:20px;
    }
input, button, select, option, textarea {
    font-size: 100%;
}
</style>
<br>
<H2> Main Page </H2>
 <img src="<?php echo $_SESSION['pix']; ?>" alt="It's my picture"  class="avatar"/>
<br><br>
Welcome  <b> <?php echo $_SESSION['firstname']. " ".$_SESSION['lastname']."."; ?>  </b>

<br><br><br><br>
 <a href="logout.php">Logout</a> 
</body>
</html> 

login.php

<?php
include 'connect_to_database.php'; //connect the connection page
if(empty($_SESSION)) // if the session not yet started 
   session_start();


if(isset($_SESSION['username'])) { // if already login
   header("location: home.php"); // send to home page
   exit; 
}

?>
<html>
<head></head>
<body>
<style>
body {
    background-color: lightgreen;
    font-family:arial;
    font-size:20px;
}
   input, button, select, option, textarea {
    font-size: 100%;
}

</style>
<br>
<h2> Login System with Pictures in PHP and MySQLi</h2>
<form action = 'login_process.php' method='POST'>
  Enter   Username:   &nbsp;
 <input type="text" name="username" />  <br><br>
    Enter Password: &nbsp;
 <input type="password" name="password" />
<br> <br>
<input type = "submit" name="submit" value="Ok" />  
</form>
</body>
</html>


login_process.php

<html>
<body>
<style>
body {
    background-color: lightgreen;
    font-family:arial;
    font-size:20px;
}
</style>
<?php
error_reporting(0);
include 'connect_to_database.php'; //connect the connection page
  
  $username = $_POST['username'];
  $password = $_POST['password'];
if(empty($_SESSION)) // if the session not yet started 
   session_start();
if(!isset($_POST['submit'])) { // if the form not yet submitted
   header("Location: login.php");
   exit; 
}

  $query = "SELECT * FROM `users` WHERE username='$username'
and password='$password'";
$result = mysqli_query($connect,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
        if($rows==1){
              
    $row2  = mysqli_fetch_array($result);
               
        $_SESSION['username'] = $_POST['username'];
      
                 $_SESSION['lastname'] = $row2['lastname'];
         $_SESSION['firstname']= $row2['firstname'];
$_SESSION['pix'] =$row2['pix'];
                 header("Location: home.php");
             
        } else{ // if not a valid user  
            echo "<br>";
            echo "<h2> Invalid Password !!! Try Again </h2>"; 
            echo "<br>";
            echo "<font name='arial'> <font size='5'>";
            echo "<a href='logout.php'>Return To Login Page</a> " ;
            echo "</font></font>";
        }
   

?>

</body>
</html>


logout.php

<?php
session_start();
unset($_SESSION['username']);
session_destroy();

header("Location: login.php");
exit;
?>


users.sql

-- phpMyAdmin SQL Dump
-- version 4.7.7
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Mar 06, 2018 at 09:39 AM
-- Server version: 10.1.30-MariaDB
-- PHP Version: 7.2.2

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
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: `login`
--

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(200) NOT NULL,
  `password` varchar(200) NOT NULL,
  `lastname` varchar(200) NOT NULL,
  `firstname` varchar(200) NOT NULL,
  `pix` varchar(500) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`, `lastname`, `firstname`, `pix`) VALUES
(1, 'jake', 'jake', 'POMPERADA', 'JAKE', '/login/images/jake.jpg'),
(2, '123', '123', 'POMPERADA', 'JACOB SAMUEL', '/login/images/jacob.jpg'),
(3, 'iya', 'iya', 'POMPERADA', 'JULIANNA RAE', '/login/images/iya.jpg'),
(4, 'allie', 'allie', 'POMPERADA', 'MA. JUNALLIE', '/login/images/allie.jpg'),
(5, 'bill', 'bill', 'GATES', 'WILLIAM', '/login/images/gates.jpg'),
(6, 'peter', 'peter', 'NORTON', 'PETER', '/login/images/norton.jpg');

--
-- Indexes for dumped tables
--

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

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
COMMIT;

/*!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 */;