Friday, December 28, 2018

PERSONNEL RECORD APPLICATION IN PHP AND MYSQL

A simple personnel record application that I wrote in PHP and MySQL in my spare time. 

I am currently accepting programming work, it projects, school 

programming projects, thesis and capstone projects, IT consulting 

work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.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.

My personal website is http://www.jakerpomperada.com





Sample Program Output



Program Listing

db.php

<?php 

$host = "localhost";
$username = "root";
$password = "";
$dbname = "db";

$con = mysqli_connect($host, $username, $password, $dbname);

if (!$con) {
die("Connection failed" . mysqli_errno($con));
}

 ?>

index.php

<?php 

// including the database connection
include_once 'db.php';


// Inserting data into the database if submit button is clicked
if (isset($_POST['submit'])) {
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$email = $_POST['email'];
$date_of_birth = $_POST['dob'];
    
    $first_name = strtoupper($first_name);
    $last_name = strtoupper($last_name);
    $email =strtolower($email);

if (!empty($first_name && $last_name && $email && $date_of_birth)) {
$insert_query = mysqli_query($con, "INSERT INTO users(f_name, l_name, email, dob) VALUES('$first_name', '$last_name', '$email', '$date_of_birth')");
if ($insert_query > 0) {
$msg = "Record Successfully Added to the Database";
}else {
$msg = "Submission Failed";
}
}
}


// update data if update button is clicked
if (isset($_POST['update'])) {
  $first_name = $_POST['fname'];
  $last_name = $_POST['lname'];
  $email = $_POST['email'];
  $date_of_birth = $_POST['dob'];
  $hidden_id = $_POST['hidden_id'];
   
  $first_name = strtoupper($first_name);
  $last_name = strtoupper($last_name);
  $email =strtolower($email);
  
  if (!empty($first_name && $last_name && $email && $date_of_birth)) {
    
    $update_query = mysqli_query($con, "UPDATE users SET f_name ='$first_name', l_name ='$last_name', email ='$email', dob ='$date_of_birth' WHERE id ='$hidden_id'");
   
    if ($update_query > 0) {
     
      $msg = "Database record updated successfully";
    
     }else {
      $msg = "Database record Update Failed";
    }
  }
}

 ?>


<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Crud Apllication</title>
    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/custom.css" rel="stylesheet">

    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootbox.min.js"></script>


</head>

 <body>

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
             <p class="" style="margin-left: 360px; color: white; padding-top: 6px; font-size: 20px;"><?php if (isset($msg)) echo $msg; ?></p>
            </div>
            
        </div>
        <!-- /.container -->
    </nav>

    <!-- Page Content -->
    <div class="container">

          <div class="row"> 
            <div class="col-md-12">
                <h1 class="page-header text-center">
                    PERSONNEL RECORD APPLICATION IN PHP AND MYSQL
                    <br>
                    <small>Create, Read, Update & Delete Database Records</small>
            </div>

           </div>
        

            <form class="form-horizontal" action="" method="POST" >    
                <div class="form-group">
                    <div class="col-md-4 col-md-offset-2">
                        <input type="text" name="fname" class="form-control " placeholder="First Name" value="<?php if (isset($first_name)) echo $first_name;?>" auto="off">
                    </div>

                    <div class="col-md-4">
                        <input type="text" name="lname" class="form-control" placeholder="Last Name" value="<?php if (isset($last_name)) echo $last_name;?>">
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-4 col-md-offset-2">
                        <input type="email" name="email" class="form-control " placeholder="Email Address" value="<?php if (isset($email)) echo $email;?>">
                    </div>

                    <div class="col-md-4">
                        <input type="date" name="dob" class="form-control" placeholder="Date of Birth" value="<?php if (isset($dob)) echo $dob;?>">
                    </div>
                </div>
                <div class="form-group">
               <div class="col-md-8 col-lg-offset-2">
                <button class="btn btn-block btn-success btn-lg" name="submit" type="submit">Add Record<span class="glyphicon glyphicon-chevron-right"></span></button>
                </div>
               </div>
            </form>
           
            <hr>
       
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-responsive">
                <thead>
                    <tr class="success">
                        <th>Personnel ID Number</th>
                        <th>Full Name</th>
                        <th>Email</th>
                        <th>Date of Birth</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>

                <?php
                  $i = 0; 
                      $read_query = mysqli_query($con, "SELECT * FROM users");
                        while ($rows = mysqli_fetch_assoc($read_query)) { 
                        $i++; ?>
               
                      <tr>
                      <td><?php echo $i; ?></td>
                      <td><?php echo $rows['f_name']."&nbsp;".$rows['l_name']; ?></td>
                        <td><?php echo $rows['email']; ?></td>
                        <td><?php echo $rows['dob']; ?></td>
                        <td>
                            <a href="update.php?update=<?php echo $rows['id'];?>" class="btn btn-primary">Update</a>
                            &nbsp&nbsp
            <a class="delete text-danger" data-id="<?php echo $rows['id']; ?>" href="javascript:void(0)">
                <i class="glyphicon glyphicon-trash"></i>
                </a>
                        </td>
                       </tr>


                    <?php }    ?>

                 
                </tbody>
            </table>
        </div>

    </div>

</body>

<script src="js/myscript.js"></script>

</html>


update.php

<?php 

// including the database connection
include_once 'db.php';


// show users details if update button is clicked
if (isset($_GET['update'])) {
  $update_id = $_GET['update'];
  $user_data = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM users WHERE id='$update_id'"));
  $first_name = $user_data['f_name'];
  $last_name = $user_data['l_name'];
  $email = $user_data['email'];
  $dob = $user_data['dob'];
}


 ?>


<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Crud Application</title>
    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/custom.css" rel="stylesheet">
    
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>

 <body>

  <style type="text/css">
        body{
              padding-top: 30px;
        }
  </style>

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
             <p class="" style="margin-left: 350px; color: white; padding-top: 6px;"><?php if (isset($msg)) echo $msg; ?></p>
            </div>
            
        </div>
        <!-- /.container -->
    </nav>

    <!-- Page Content -->
    <div class="container">

          <div class="row">  <!-- Blog Entries Column -->
            <div class="col-md-12">
                <h1 class="page-header text-center">
                    PERSONNEL RECORD APPLICATION IN PHP AND MYSQL
                    <br>
                    <small>Update Database Records</small>
            </div>

           </div>
        

            <form class="form-horizontal" action="index.php" method="POST" >    
                <div class="form-group">
                    <div class="col-md-4 col-md-offset-2">
                        <input type="text" name="fname" class="form-control " placeholder="First Name" value="<?php if (isset($first_name)) echo $first_name;?>">
                    </div>

                    <div class="col-md-4">
                        <input type="text" name="lname" class="form-control" placeholder="Last Name" value="<?php if (isset($last_name)) echo $last_name;?>">
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-4 col-md-offset-2">
                        <input type="email" name="email" class="form-control " placeholder="Email Address" value="<?php if (isset($email)) echo $email;?>">
                    </div>

                    <div class="col-md-4">
                        <input type="date" name="dob" class="form-control" placeholder="Date of Birth" value="<?php if (isset($dob)) echo $dob;?>">
                    </div>

                    <input type="hidden" name="hidden_id" value="<?php if (isset($_GET['update'])) echo $_GET['update']; ?>">

                </div>
                <div class="form-group">
               <div class="col-md-8 col-lg-offset-2">
                <button class="btn btn-block btn-info btn-lg" name="update" type="submit">Update Record<span class="glyphicon glyphicon-chevron-right"></span></button>
                <hr class="text-danger">
                </div>
               </div>
            </form>
           
            <hr>
       
    </div>

</body>

</html>

delete.php

<?php

include_once 'db.php';
if ($_REQUEST['delete']) {
$d_id = $_REQUEST['delete'];
$delete_query = mysqli_query($con, "DELETE FROM users WHERE id='$d_id'");
        
        if ($delete_query > 0) {
echo "Record Deleted Successfully From the Database...";
}
}


db.sql


-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Dec 28, 2018 at 07:23 AM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.3.0

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: `db`
--

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

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

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `f_name` varchar(200) NOT NULL,
  `l_name` varchar(200) NOT NULL,
  `email` varchar(200) NOT NULL,
  `dob` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

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

INSERT INTO `users` (`id`, `f_name`, `l_name`, `email`, `dob`) VALUES
(4, 'JAKE RODRIGUEZ', 'POMPERADA', 'jakerpomperada@gmail.com', '1978-06-08'),
(5, 'JACOB SAMUEL', 'POMPERADA', 'jacobsamuel@yahoo.com', '2013-04-19'),
(6, 'JULIANNA RAE', 'POMPERADA', 'iyapomperada@aol.com', '2014-07-04'),
(7, 'MA. JUNALLIE ', 'POMPERADA', 'alliefpomperada@gmail.com', '1971-08-25');

--
-- 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=8;
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 */;








Monday, December 24, 2018

EMPLOYEES CONTACT DETAILS SYSTEM IN C

A very simple program that I wrote using C language to manage the information of the employee's contact details. I wrote this code in the Christmas Eve December 24, 2018, to make my day productive and enjoyable. I hope you will find my work useful. Merry Christmas to all you guys.

I am currently accepting programming work, it projects, school 

programming projects, thesis and capstone projects, IT consulting 

work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.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.

My personal website is http://www.jakerpomperada.com












Sample Program Output


Program Listing

/*employees_details.c
 Authors   : Jake R. Pomperada,MAED-IT 
 Emails    : jakerpomperada@gmail.com 
 Tool      : Dev C++ Version 5.11
 Date      : December 24, 2018  Monday  11:46 PM
 */

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

main( )
{
FILE  *fp, *ft ;
char  another, choice ;
struct employees
{
char  emp_id[200];
char  name[200];
char  sex;
char  address[200];
char  telephone[200];
char  mobile[200];
char  email[200];
};

struct employees info ;
char employee_id[200];
int flag=0;

long int  recsize ;
fp = fopen ("RECORDS.DAT", "rb+" ) ;

if ( fp == NULL )
{
fp = fopen ("RECORDS.DAT", "wb+" ) ;

if ( fp == NULL )
{
puts ("Cannot open file" ) ;
exit(0) ;
}
}

recsize = sizeof ( info ) ;

while (1)
{
        system("CLS");
        printf("\n");
        printf("\n\t===========================================");
        printf("\n\t\tEMPLOYEES CONTACT DETAILS SYSTEM ");
        printf("\n\t\t\tCreated By");
        printf("\n\tJake R. Pomperada and Kristine T. Soberano");
        printf("\n\t===========================================");
printf("\n\n");
printf ( "\t1. ADD EMPLOYEE'S RECORD") ;
printf("\n");
printf ( "\t2. DISPLAY EMPLOYEE'S RECORD" ) ;
printf("\n");
printf ( "\t3. UPDATE EMPLOYEE'S RECORD" ) ;
printf("\n");
printf ( "\t4. SEARCH EMPLOYEE'S RECORD" ) ;
printf("\n");
printf ( "\t5. DELETE EMPLOYEE'S RECORD" ) ;
printf("\n");
printf ( "\t6. QUIT PROGRAM" );
printf("\n\n\n");
printf ("\tSELECT YOUR CHOICE : ") ;
fflush (stdin) ;
choice = getche() ;
switch (choice)
{
case '1' :
fseek (fp, 0 ,SEEK_END) ;
another = 'Y' ;
while ( another == 'Y' )
{
system("cls");
printf("\n\n");
                    printf("\t=== Add New Employee's Record in the Database ===");
                    printf("\n\n");
printf("\tEnter Employees ID Number    : ");
scanf("%s",&info.emp_id);
printf("\tEnter Employee's Name        : ");
fflush(stdin);
gets(info.name);
printf("\tEnter Gender M/F             : ") ;
                    info.sex = toupper(getche());
                    printf("\n");
                    printf("\tEnter Home Address           : ");
                    fflush(stdin);
gets(info.address);
printf("\tEnter Telephone Number       : ");
                    fflush(stdin);
gets(info.telephone);
printf("\tEnter Mobile Number          : ");
                    fflush(stdin);
gets(info.mobile);
printf("\tEnter Email Address          : ");
fflush(stdin);
gets(info.email);
    fwrite (&info, recsize, 1, fp ) ;
printf("\n\n");
printf ("\n\tAdd another Record (Y/N)  : ") ;
fflush (stdin) ;
another = toupper(getche()) ;
}

break ;

case '2' :
    system("cls");
rewind (fp);
printf("\n\n");
                printf("\t=== View Employee's Records in the Database ===");
                printf("\n");
while ( fread ( &info, recsize, 1, fp ) == 1 )
         {
    printf("\n\tEmployee's ID Number  : %s",info.emp_id);
        printf("\n\tEmployee's Name       : %s",info.name);
    printf("\n\tGender                : %c",info.sex);
    printf("\n\tHome Address          : %s",info.address);
    printf("\n\tTelephone Number      : %s",info.telephone);
    printf("\n\tMobile Number         : %s",info.mobile);
    printf("\n\tEmail Address         : %s",info.email);
        printf("\n\n");
        }
            system("pause");
            break ;

case '3' :
               rewind (fp);
another = 'Y' ;
while (another == 'Y')
{
                    system("cls");
                    printf("\n\n");
                    printf("\t=== Update Employee's Records in the Database ===");
                    printf("\n\n");
    printf("\tEnter Employee's ID Number    : ");
scanf("%s",&employee_id);
printf("\n");
rewind (fp) ; 
while (fread( &info, recsize, 1, fp ) == 1 )
{
                    if ( strcmp (info.emp_id, employee_id ) == 0 )
                    {
                    printf("\tEnter Employee's ID Number    : ");
scanf("%s",&info.emp_id);
printf("\tEnter Employee's Name         : ");
fflush(stdin);
gets(info.name);
printf("\tEnter Gender M/F              : ") ;
                    info.sex = toupper(getche());
                    printf("\n");
                    printf("\tEnter Home Address            : ");
                    fflush(stdin);
gets(info.address);
printf("\tEnter Telephone Number        : ");
                    fflush(stdin);
gets(info.telephone);
printf("\tEnter Mobile Number           : ");
                    fflush(stdin);
gets(info.mobile);
printf("\tEnter Email Address           : ");
fflush(stdin);
gets(info.email);
                    printf("\n\n");
                    printf("\tEmployee's records has been updated in the database.");
                    printf("\n\n");
                    system("pause");
fseek ( fp, - recsize, SEEK_CUR ) ;
fwrite ( &info, recsize, 1, fp ) ;
break ;
                    }
                }
             if (strcmp(info.emp_id,employee_id) != 0 )
                    {
                        printf("\n\n");
                        printf("\tNo Record in the Database.");
                        printf("\n");
                        system("pause");
                        break;
                    }
                    printf("\n\n");
printf ("\n\tUpdate Another Record (Y/N) : " ) ;
fflush (stdin) ;
another = toupper(getche());
}
break ;
case '4' :
                rewind (fp);
another = 'Y' ;
while ( another == 'Y' )
{
                  system("cls");
printf("\n\n");
                    printf("\t=== Search Employee's Records in the Database ===");
                    printf("\n\n");
    printf("\tEnter Employee's ID Number     : ");
scanf("%s",&employee_id);
    rewind (fp) ;
    printf("\n");
while (fread( &info, recsize, 1, fp ) == 1 )
{
if (strcmp(info.emp_id,employee_id) == 0 )
{
                        printf("\n\tEmployee's ID Number  : %s",info.emp_id);
        printf("\n\tEmployee's Name       : %s",info.name);
        printf("\n\tGender                : %c",info.sex);
        printf("\n\tHome Address          : %s",info.address);
    printf("\n\tTelephone Number      : %s",info.telephone);
    printf("\n\tMobile Number         : %s",info.mobile);
    printf("\n\tEmail Address         : %s",info.email);
                        printf("\n\n");
                        system("pause");
                        break;
                }
}

            if (strcmp(info.emp_id,employee_id) != 0 )
                    {
                        printf("\n");
                        printf("\tSorry No Record Found in the Database.");
                        printf("\n\n");
                        system("pause");
                        break;
                    }
                    printf("\n");
printf ("\n\tSearch Another Employee's Record? (Y/N) : " ) ;
fflush (stdin) ;
another = toupper(getche());
}
break ;

case '5' :
another = 'Y' ;
while ( another == 'Y' )
{
system("cls");
flag=0; 
printf("\n\n");
                    printf("\t=== Delete Employee's Records in the Database ===");
                    printf("\n\n");
printf("\tEnter Employee's ID Number      : ");
scanf("%s",&employee_id);
printf("\n");
    ft = fopen ("TEMP.DAT", "wb") ;
rewind (fp) ;
while (fread (&info, recsize, 1, fp) == 1 )
{
if (strcmp(info.emp_id, employee_id) != 0 )
fwrite(&info, recsize, 1, ft ) ;
else
                            flag=1;
}
fclose (fp) ;
fclose (ft) ;
remove ("RECORDS.DAT") ;
rename ("TEMP.DAT", "RECORDS.DAT") ;
fp = fopen ("RECORDS.DAT", "rb+") ;
                  if(flag==1) {
                        printf("\n\n");
                        printf("\tRecord Successfully Deleted From the Database.");
                        printf("\n\n");
                        system("pause");
                    }
else if (flag!=1) {
                        printf("\n\n");
                        printf("\tSorry Record Not Found in the Database.");
                        printf("\n\n");
                        system("pause");
                    }
                        printf("\n\n");
                        printf( "\tDelete Another Employee's Record? (Y/N) " ) ;
                        fflush ( stdin ) ;
                        another = toupper(getche());
}
break ;
case '6' :
fclose (fp) ;
printf("\n\n");
printf("\t\tThank You For Using This Program !!!   ");
printf("\n\n");
system("PAUSE");
exit(0);
}
}
} /* End of the Code */