Monday, March 5, 2018

User Record System in PHP and MySQLI

A simple crud application that I wrote using PHP and MySQLI which is already compliant with the new version of PHP.  

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

add.php

<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
    <title>User Record System Using PHP and MySQLI</title>


</head>
<body>

<?php
 require_once 'connections.php';

if($_POST) {
    $name = $_POST['name'];
    $age = $_POST['age'];

    $sql = "INSERT INTO person (name,age) VALUES ('$name', '$age')";
    if($connect->query($sql) === TRUE) {
echo "<p>New Record Successfully Created</p>";
        echo "<a href='create.php'><button type='button'>Back</button></a>";
        echo "<a href='index.php'><button type='button'>Home</button></a>";
    } else {
        echo "Error " . $sql . ' ' . $connect->connect_error;
    }

    $connect->close();
}

  
?>
</body>
</html>


delete.php

<?php 

require_once 'connections.php';

if($_GET['id']) {
$id = $_GET['id'];

$sql = "SELECT * FROM person WHERE id = {$id}";
$result = $connect->query($sql);
$data = $result->fetch_assoc();

$connect->close();
?>

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<title>Delete User Record</title>
</head>
<body>

<h3>Do you really want to delete the record of
<?php echo strtoupper($data['name'].'?');  ?>
</h3>
<form action="remove.php" method="post">

<input type="hidden" name="id" value="<?php echo $data['id'] ?>" />
<button type="submit">Ok</button>
<a href="index.php"><button type="button">Back</button></a>
</form>

</body>
</html>

<?php
}
?>

edit.php

<?php 

require_once 'connections.php';

if($_GET['id']) {
$id = $_GET['id'];

$sql = "SELECT * FROM person WHERE id = {$id}";
$result = $connect->query($sql);

$data = $result->fetch_assoc();

$connect->close();

?>

<!DOCTYPE html>
<html>
<head>
<title>Edit Users</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>

<fieldset>
<legend>Edit Users</legend>

<form action="update.php" method="post">
<table cellspacing="0" cellpadding="0">
<tr>
<th>Name</th>
<td><input type="text" name="name" placeholder="Name" value="<?php echo $data['name'] ?>" /></td>
</tr>
<tr>
<th>Age</th>
<td><input type="text" name="age" placeholder="Age" value="<?php echo $data['age'] ?>" /></td>
</tr>
<tr>
<input type="hidden" name="id" value="<?php echo $data['id']?>" />
<td ><button id="someTable" type="submit">Save Changes</button>&nbsp;&nbsp;
<a href="index.php"><button type="button">Back</button></a></td>
</tr>
</table>
</form>

</fieldset>

</body>
</html>

<?php
}
?>


index.php

<html>
<?php require_once 'connections.php'; ?>
<!DOCTYPE html>
<<br>
 <h3 align="center"> User Record System Using PHP and MySQLI </h3>html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
    <title>User Record System Using PHP and MySQLI</title>


</head>
<body>
 <br>
<div class="manageUser">
    <a href="create.php"><button type="button">Add User</button></a>
    <table border="1" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <th>Name</th>
                <th>Age</th>
<th>Option</th>
                
            </tr>
        </thead>
        <tbody>
             <?php
            $sql = "SELECT * FROM person";
            $result = $connect->query($sql);

            if($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<tr>
                        <td>".$row['name']."</td>
                        <td>".$row['age']."</td>
                         <td>
                            <a href='edit.php?id=".$row['id']."'><button type='button'>Edit</button></a>
                            <a href='delete.php?id=".$row['id']."'><button type='button'>Remove</button></a>
                        </td>
                    </tr>";
                }
            } else {
                echo "<tr><td colspan='5'><center>No Data Avaliable</center></td></tr>";
            }
            ?>
        </tbody>
    </table>
</div>

</body>
</html>

update.php

<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
    <title>User Record System Using PHP and MySQLI</title>


</head>
<body>

<?php 

require_once 'connections.php';

if($_POST) {
$name = $_POST['name'];
$age = $_POST['age'];
$id = $_POST['id'];

$sql  = "UPDATE person SET name = '$name',age = '$age' WHERE id = {$id}";
if($connect->query($sql) === TRUE) {
echo "<p>Succcessfully Updated</p>";
echo "<a href='edit.php?id=".$id."'><button type='button'>Back</button></a>";
echo "<a href='index.php'><button type='button'>Home</button></a>";
} else {
echo "Erorr while updating record : ". $connect->error;
}

$connect->close();

}

?>

</body>
</html>


connections.php

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

// 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";
}
  
?>


create.php

<!DOCTYPE html>
<html>
<head>
    <title>Add Member</title>

    <link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>

<fieldset>
    <legend>Add User</legend>

    <form action="add.php" method="post">
        <table cellspacing="0" cellpadding="0">
            <tr>
                <th>Name</th>
                <td><input type="text" name="name" placeholder="Name" /></td>
            </tr>     
            <tr>
                <th>Age</th>
                <td><input type="text" name="age" placeholder="Age" /></td>
            </tr>
            
            <tr>
                <td><button type="submit">Save Changes</button></td>
                <td><a href="index.php"><button type="button">Back</button></a></td>
            </tr>
        </table>
    </form>

</fieldset>

</body>
</html>

remove.php

<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
    <title>User Record System Using PHP and MySQLI</title>


</head>
<body>
<?php 

require_once 'connections.php';

if($_POST) {
$id = $_POST['id'];

$sql = "DELETE FROM person WHERE  id = {$id}";
if($connect->query($sql) === TRUE) {
echo "<link rel='stylesheet' type='text/css href='mystyle.css'>";
echo "<p>Record Sucessfully Remove from the Database !!!</p>";
echo "<a href='index.php'><button type='button'>Back</button></a>";
} else {
echo "Error removing record : " . $connect->error;
}

$connect->close();
}

?>

</body>
<html>

mystyle.css


            
        .manageUser {
            width: 50%;
            margin: auto;
        }

        table {
font-family:arial;
font-weight:bold;
size:18px;
            width: 100%;
            margin-top: 20px;
        }

        body {
background-color:lightgreen;
font-family:arial;
font-weight:bold;
size:18px;
}
fieldset {
margin: auto;
margin-top: 100px;
width: 50%;
}

table tr th {
padding-top: 10px;
}
user.sql

-- phpMyAdmin SQL Dump -- version 3.1.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Jan 04, 2014 at 06:55 AM -- Server version: 5.1.30 -- PHP Version: 5.2.8 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!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 utf8 */; -- -- Database: `user` -- -- -------------------------------------------------------- -- -- Table structure for table `person` -- CREATE TABLE IF NOT EXISTS `person` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `age` int(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `person` -- INSERT INTO `person` (`id`, `name`, `age`) VALUES (1, 'Manuel Uy', 36), (2, 'Jorge Vargas', 12), (3, 'Maria Buenavista', 22);










Sunday, March 4, 2018

List of Armstrong Number in Java

A very simple program to list down the Armstrong numbers in Java.

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


public class Main {

    public static void main(String[] args) {
        int a =0;
        int num =0;

        int n, sum, temp, remainder, digits;

        int start = 100;
        int end =2000;

        System.out.println("\n\n");
        System.out.print("List of Armstrong Number in Java");
        System.out.println("\n");

        for (int i = start; i <= end; i++) {

            sum = 0;
            digits = 0;

            temp = i;

            while (temp != 0) {
                digits++;
                temp = temp / 10;
            }

            temp = i;

            while (temp != 0) {
                remainder = temp % 10;
                sum = sum + power(remainder, digits);
                temp = temp / 10;
            }

            if (i == sum)
                System.out.println(i + " is an Armstrong number.");

        }
        System.out.println();
        System.out.print("End of Program");
        System.out.println();
    }

    static int power(int n, int r) {
        int c, p = 1;

        for (c = 1; c <= r; c++)
            p = p * n;

        return p;
    }

    }

 

 

 

List of Prime Number in Java

A very simple program to list down the prime numbers from 1 to 220 using Java as our 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
 
public class Main {

    public static void main(String[] args) {
        int a =0;
        int num =0;

        System.out.println("\n\n");
        System.out.print("List of Prime Number in Java");
        System.out.println("\n");

        String  primeNumbers = "";

        for (a = 1; a <= 220; a++)
        {
            int counter=0;
            for(num =a; num>=1; num--)
            {
                if(a%num==0)
                {
                    counter+=1;
                }
            }
            if (counter ==2)
            {

                primeNumbers += a + " ";
            }
        }
        System.out.println("Prime numbers from 1 to 220 are :");
        System.out.println(primeNumbers);
        System.out.println();
        System.out.print("End of Program");
        System.out.println();
    }
}


Saturday, March 3, 2018

Name Greeter in Spring Boot

I am just a beginner in Spring MVC and Spring Boot this code will show how to mapped and pass a name and display on the template webpage.  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 is  +63 (034) 4335675.




Sample Program Output


Program Listing

Demoapplication.java

package com.jake.demoapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplicationpublic class DemoappApplication {

   public static void main(String[] args) {
      SpringApplication.run(DemoappApplication.class, args);
   }
}

GreetingController.java

package com.jake.demoapp;

/** * Created by Jacob on 3/3/2018. */
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {
    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value = "name", required = false, defaultValue = "World !!!") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }

}

greeting.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Serving Web Content</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<style>
    p {
        font-family: Arial;
        font-weight: bold;
        size:25px;
        color:blue;
    }
</style>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>






Friday, March 2, 2018

Perfect Number in C

In this article is another simple program to show you how to solve perfect number using C language. The code is very simple and easy to understand I am using Code Blocks to write this code.

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 is  +63 (034) 4335675.





Sample Program Output



Program Listing

perfect.c

#include <stdio.h>

int main()
{
    int number=0, rem=0, sum = 0, a=0;

    printf("Perfect Number in C");
    printf("\n\n");
    printf("Enter a Number : ");
    scanf("%d", &number);
    for (a = 1; a <= (number - 1); a++)
    {
        rem = (number % a);
if (rem == 0)
        {
            sum = sum + a;
        }
    }
    if (sum == number) {
        printf("\n\n");
        printf("The given number %d is perfect number.", number);
        printf("\n\n");
    }
    else {
        printf("\n\n");
        printf("The given number %d is not a perfect number.",number);
        printf("\n\n");
    }
     printf("\n\n");
    return 0;

}



Student Record System in C++

A very simple code to accept and display student profile using C++. I am using structure to hold and display it to the screen.

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 is  +63 (034) 4335675.



Program Listing

struct.cpp


#include <iostream>

using namespace std;

struct new_person {
    string name,address;
    int age;
};

main() {
    new_person sample;

    cout << "Enter your name : ";
    getline(cin,sample.name);
    cout << "\nEnter your Address : ";
    getline(cin,sample.address);
    cout << "\nEnter your Age : ";
    cin >> sample.age;


    cout << "\n\nName    : " << sample.name;
    cout << "\n\nAddress : " << sample.address;
    cout << "\n\nAge     : " << sample.age;
    cout << "\n\n";
    system("pause");
}

Student Grading System Using Text File in C++

A very simple program that I wrote a long time ago to compute and store the student grade in a text file using C++. I am using Code Blocks as my text editor and Dev C++ as my C++ compiler in this program.

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 is  +63 (034) 4335675.



Program Listing.

student_grade.cpp

#include <iostream>
#include <fstream>

using namespace std;

float grade(float pre, float med, float end)
{
   float compute=0;
  compute = (pre * 0.30) + (med * 0.30) + (end * 0.40);
  return(compute);
}

 main() {
      ofstream myfile("grade.txt");
      string name,course;
      float pre1=0.00, med1=0.00,end1=0.00;
      cout << "\n\t Student Grading System 1.0";
      cout << "\n\n";
      cout << "Enter Student Name    : ";
      getline(cin,name);
      cout << "Enter Student Course : ";
      getline(cin,course);
      cout << "Enter Prelim Grade    : ";
      cin >> pre1;
      cout << "Enter Midterm Grade   : ";
      cin >> med1;
      cout << "Enter Midterm Grade   : ";
      cin >> end1;
      cout << "\n\n";
      cout << "Final Grade "
           << grade(pre1,med1,end1)
           << ".";
      cout << "\n\n";
      myfile << "\n======================";
      myfile << "\n Student Grade Report ";
      myfile << "\n====================== ";
      myfile << "\n\n";
      myfile << "\nStudent Name   : " << name;
      myfile << "\nStudent Course : " << course;
      myfile << "\n\n";
      myfile << "\nPrelim  Grade   : " << pre1;
      myfile << "\nMidterm Grade   : " << med1;
      myfile << "\nEndterm Grade   : " << end1;
      myfile << "\n\n";
      myfile << "Final Grade "
           << grade(pre1,med1,end1)
           << ".";
      myfile.close();
      system("pause");
 }


Stack Function Call in C

A very simple program in C language to show how to call a function using stack.

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 is (034) 4335675.




Program Listing

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>

unsigned int far *ptr ;
void ( *p )( void ) ;

void f1( ) ;
void f2( ) ;

void main( )
{
f1( ) ;
f2( ) ;

printf ( "\nback to main..." ) ;
exit ( 1 ) ;
}

void f1( )
{
ptr = ( unsigned int far * ) MK_FP ( _SS, _SP + 2 ) ;
printf ( "\n%d", *ptr ) ;

p = ( void ( * )( ) ) MK_FP ( _CS, *ptr ) ;
( *p )( ) ;
printf ( "\nI am f1( ) function " ) ;
}

void f2( )
{
printf ( "\nI am f2( ) function" ) ;
}