Saturday, July 18, 2015

Users Details System in JSP and MySQL

There are many web scripting programming language in this world one of its based of Java programming language it is called Java Server Pages or JSP. It is entirely based on Java technology to be specific Servlets which interacts together with the web server. In Java the most common web server is Apache Tomcat which is also an open source web server. One of the benefits of learning how to program in JSP is that almost all Java Enterprise application works with JSP and it is easy to learn and implement with database application such as MySQL.

In this article I will not only show you how to create a basic CRUD application in Java Server Pages but also how it is being done through the use of my program codes. Basically I am using NetBeans 8.1.0 as my IDE or Integrated Development Environment in writing this database application and also I download mysql java connector which I include a link in my article. My program that I wrote is a typical database routine Create, Retrieve, Update and Delete or CRUD using JSP and MySQL.

The code is very short in terms of number of lines of instruction and the same way I make sure it is very easy to understand and use in your programming projects that utilize JSP and MySQL as your tool. The application will accept the name of the person, city address and telephone number it is just like an address book or mailing list application.

It has been along while since I was able to achieve this program I have some difficulty also in learning Java and JSP along the way but through dedication and perseverance I was able to get it. That's why I am sharing this to my fellow software developers.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.










Sample Program Output


list.jsp

<%-- list.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*"%>

<head><title>Users Details System</title>
</head>
<style>
    h2 {
        text-align:center;
        font-family: arial;
        color: red;
       };
    td {
        text-align:center;
        font-family: arial;
        font-size: 16;
    };
   
</style>    
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;  "
            + "}; </style>");

out.println("<style>  a.space {font-family: arial;"
           + " color: blue; font-size: 18;  "
            + "margin:0 0 0 208px;}; </style>");

%>
<body>

<div align="center" width="200%">
    <br>
    <h2>USERS DETAILS SYSTEM</h2>
    <br>
    <div align="left" width="200%">
<% out.println("<a class='space' href='insert.jsp'> ADD RECORD </a>");  %>  
    </div>
<br>
<table border="1" borderColor="black" cellPadding="0" cellSpacing="0" width="920" height="80">
<tbody>
<td bgColor="cyan" width="150" align="center" height="19"><font color="red"><b>
Student No.</b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>NAME</b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>CITY</b></font></td>
<td bgColor="cyan" width="230" height="19"><font color="red"><b>PHONE</b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>ACTIONS </b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>TAKEN </b></font></td>
<%
String DRIVER = "com.mysql.jdbc.Driver";
Class.forName(DRIVER).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try{
  
String url="jdbc:mysql://localhost:3306/users?user=root&password=";
int i=1;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
rst=stmt.executeQuery("SELECT * FROM student_info ORDER BY name ASC ");
while(rst.next()){

if (i==(i/2)*2){
%>
<tr>
<td bgColor="lightgreen" vAlign="top" width="80"  height="19"><%=i%></td>
<td bgColor="lightgreen" vAlign="top" width="110" height="19"><%=rst.getString(2)%></td>
<td bgColor="lightgreen" vAlign="top" width="224" height="19"><%=rst.getString(3)%></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19"><%=rst.getString(4)%></td>
<td bgColor="lightgreen" vAlign="top" width="220" height="19" >
    <a href="edit.jsp?id=<%=rst.getInt("id")%>"> Edit Record </a></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19">
    <a href="delete.jsp?id=<%=rst.getInt("id")%>"> Delete Record </a></td>
</tr>
<%
}else{
%>
<tr>
<td bgColor="lightgreen" vAlign="top" width="80" align="center" height="19"><%=i%></td>
<td bgColor="lightgreen" vAlign="top" width="107" height="19"><%=rst.getString(2)%></td>
<td bgColor="lightgreen" vAlign="top" width="224" height="19"><%=rst.getString(3)%></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19"><%=rst.getString(4)%></td>
<td bgColor="lightgreen" vAlign="top" width="220" height="19" >
    <a href="edit.jsp?id=<%=rst.getInt("id")%>"> Edit Record </a></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19">
    <a href="delete.jsp?id=<%=rst.getInt("id")%>"> Delete Record </a></td>
</tr>
<% }

i++;
}
rst.close();
stmt.close();
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
%>
</tbody>
</table>
</center>
</div>
</body>

insert.jsp

<%-- insert.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<html>
<head>
<title>Add Record </title>
</head>
<body>
<style>
    table, td, th {
    border: 1px solid green;
    font-family: arial;
    color: blue;
}

table {
    background-color: lightgreen;
   }
</style>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>

<table border="1" width="50%">
<tr>
<td width="100%">
<form method="POST" action="save.jsp">

<h2 align="center">ADD RECORD</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>Name:</b></td>
<td width="50%"><input type="text" name="name" size="50"/> </td>
</tr>
<tr>
<td width="50%"><b>City:</b></td>
<td width="50%"><input type="text" name="city" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Telephone Number:</b></td>
<td width="50%"><input type="text" name="telephone" size="15"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</form>
</td>
</tr>
</table>
<% out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
%>

</body>
</html>

save.jsp

<%-- save.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String name=request.getParameter("name");
String city=request.getParameter("city");
String telephone=request.getParameter("telephone");

int val = st.executeUpdate("INSERT student_info "
        + "VALUES(id,'"+name+"','"+city+"','"+telephone +"')");

con.close();
out.println("<p> The record of " +"<b>"+ name +"</b>" + " is successfully saved. </p>");
out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

%>

edit.jsp

<%-- edit.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<html>

<head>
<title>Update Record</title>
</head>
<style>
    table, td, th {
    border: 1px solid green;
    font-family: arial;
    color: blue;
}

table {
    background-color: lightgreen;
   }
</style>
<body>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>
<% 
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String query = "SELECT name,city,phone FROM student_info WHERE id="+id;
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
%>


<table border="1" width="50%">
<tr>
<td width="100%">
<form method="POST" action="update.jsp">
<input type="hidden" name="id" value="<%=request.getParameter("id")%>">
<h2 align="center">UPDATE RECORD</h2>
<table border="2"  width="100%" bgColor="lightgreen">

<tr>
<td width="50%" bgColor="lightgreen"><b>Name:</b></td>
<td width="50%" bgColor="lightgreen"><input type="text" name="name"
    value="<%=rs.getString("name")%>" size="50"/> </td>
</tr>
<tr>
<td width="50%" bgColor="lightgreen"><b>City:</b></td>
<td width="50%" bgColor="lightgreen"><input type="text" name="city" value="<%=rs.getString("city")%>" size="50"></td>
</tr>
<tr>
<td width="50%" bgColor="lightgreen"><b>Telephone:</b></td>
<td width="50%" bgColor="lightgreen"><input type="text" name="phone" value="<%=rs.getString("phone")%>" size="15"></td>
</tr>
</table>
<p><input type="submit" value="Update" name="submit">
<input type="reset" value="Reset" name="reset"></p>

</form>
</td>
</tr>
</table>


<%}

rs.close();
con.close();

}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
<% out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
%>
</body>
</html>

update.jsp

<%-- update.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>
<% 
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String name=request.getParameter("name");
String city=request.getParameter("city");
String phone=request.getParameter("phone");
int in = st.executeUpdate("UPDATE student_info SET name='"+name+"'"
                          + ",city='"+city+"',phone='"+phone+"' "
                          + "WHERE id='"+id+"'");
con.close();
out.println("<p> The record of " +"<b>"+ name +"</b>" + " is successfully updated. </p>");
out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>

delete.jsp

<%-- delete.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>

<% 
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String name=request.getParameter("name");
int in = st.executeUpdate("DELETE FROM student_info WHERE id='"+id+"'");
con.close();
out.println("<p> The record is successfully deleted. </p>");
out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>





Sunday, July 12, 2015

Addition of Three Numbers in C++ Using Pointers

In this article I would like to share with you a sample program that I wrote while I'm still learning how to program using pointers as my data structure. I called this program addition of three numbers using pointers what the program does is to ask the user to enter three numbers and then our program will compute for the sum of the three number being provided by our user.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.


Program Listing

#include <iostream>

using namespace std;


 int addition(int *a, int *b, int *c)
 {
     return(*a + *b + *c);
 }

 main() {
     int x=0,y=0,z=0;

     cout << "Addition Program";
     cout << "\n\n";
     cout << "Enter three numbers : ";
     cin >> x >> y >> z;
     cout << "\n\n";
     cout << "The sum of  three numbers is "
          << addition(&x,&y,&z)
          <<".";
     cout << "\n\n";
     system("pause");
 }



Finding the length of the word in C++ using Pointers

This simple program will count the number of characters in a given string or word by the user in C++ using Pointers as our data structure.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing

#include <iostream>

using namespace std;

int str_length(char *s) {
   int a=0;
   while(*s) {
       s++;
       a++;
   }
   return a;
}

main() {
    char name[100];
    cout << "Enter a Word : ";
    gets(name);
    cout << "\n\n";
    cout << "The lenght of the word is "
         << str_length(name) << ".";
    cout << "\n\n";
    system("pause");
}



Swapping of Two Numbers in C++ using Pointers

In this article I would like to share with you a  program that I wrote in C++ that will interchange or swap the arrangement of numbers using pointers as our data structure.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.


Program Listing

#include <iostream>

using namespace std;

int swap(int *a, int *b)
{
    int temp=0;

    temp = *a;
    *a = *b;
    *b = temp;
}

main() {
    int a=0,b=0;
    cout << "\t\t Swap Two Numbers ";
    cout << "\n\n";

    cout << "Enter two numbers  ==> "; swap(&a,&b);
    cout << "\n\n";
    cout <<"Swap Arragement ==> "
         << a << " " << b;
    cin >> a >> b;
    cout << "\n\n";
    cout <<"Original Arragement ==> "
           << a << " " << b;

    cout << "\n\n";
    system("pause");
}

Year Level Checker Using Pointers in C++

This sample program will determine the year level of the student using pointers in C++. The code is very simple to understand and follow.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing


#include <iostream>

using namespace std;



main ( )
{

struct  {

int year_level;

}*ptr;

cout << "Enter year level :=> ";
cin >> ptr->year_level ;
cout << "\n\n";


if (ptr-> year_level == 1) {
    cout << "You are a Freshmen";
}
else if (ptr-> year_level == 2) {
    cout << "You are a Sophomore";
}
else if (ptr-> year_level == 3) {
    cout << "You are a Junior";
}
else if (ptr-> year_level == 4)
  {
    cout << "You are a Senior";
}
else {
    cout << "Invalid Option Try Again";
}
cout << "\n\n";
system("pause");
}

Age Checker in C++

A simple program  that I wrote in C++ to check if the age of the person is minor or already an adult I wrote this code while I'm still learning how to program in C++.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing

#include <iostream>

 using namespace std;

  int ages(int a) {
      if (a >= 18) {
          cout << "You are an adult";
      }
      else
      {
      cout << "Still a Minor";
      }
  }

  main() {
      int age2[1];

      cout << "Enter your age :";
            cin >> age2[0];
      cout << "\n\n";
      ages(age2[0]);
      cout << "\n\n";
      system("pause");
  }

Student Tuition Fee Solver in PHP

A simple program that I wrote in PHP in my web programming class in college I called this program Student Tuition Fee Solver in PHP that will compute the payment of the student based on the course and units being enrolled by the student in school.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing


<!-- stud.php -->
<!-- Created By: Mr. Jake R. Pomperada, MAED-IT -->
<!-- December 14, 2012 Thursday -->
<!-- Tool : PHP -->

 <html> 
 <head><title>Student Tuition Fee Solver</title>
 
 <STYLE type="text/css">
     
      h3 { 
        font-sytle: comic sans ms;
    text-align:center;
        color: white;                /* text color is white */ 
        background: red;            /* Content, padding will be blue */
        
        padding: 12px 0px 12px 12px; /* Note 0px padding right */
        list-style: none             /* no glyphs before a list item */
                                     /* No borders set */
      }
     
    </STYLE>
 </head> 
 <?php
 error_reporting(0);

$fname = trim($_REQUEST['fname']);
$lname = trim($_REQUEST['lname']);
$gender = strip_tags($_POST['gender']);

$course = trim($_REQUEST['course']);

$units= trim($_REQUEST['units']);

$cost = trim($_REQUEST['cost']);
$paid2 = trim($_REQUEST['paid']); 

$paid = number_format($paid2,2,'.',',');

$solve = ($units * $cost);

$total_cost = number_format($solve,2,'.',',');
// Clear the text field

if ($_REQUEST['clear']){
   $fname="";
   $lname="";
   $gender="";
   $total_cost="";
   $course="";
   $units="";
   $cost="";
   $paid2="";
   $paid="";
     
}

if ($_REQUEST['change']){

$change3 = ($paid2 - $solve);

$change =number_format($change3,2,'.',',');
}

?>
 <body bgcolor="green"> 
 <font face="comic sans ms">
 <h3>Student Tuition Fee Solver</h3> 
  <form action="" method="post"> 
 <fieldset>
 <table> 
 
 <tr><td><font color="white">First Name </font> </td>  <td> </td> <td>
 <input type="text" name="fname"  value="<?php echo $fname; ?> " size="30" /></td> 
 <td ><font color="white"> Last Name </font> </td>  <td> </td> <td >
 <input type="text" name="lname" value="<?php echo $lname; ?>" size="30" /></td>
 </tr>   
 
 <tr><td><font color="white">Gender </font></td>   <td> </td> <td>

   <font color="white"> 
 
   Male </font> <input type="radio" value="Male" name="gender" id="gender" 
<?php  if ($_POST ['gender']=='Male') echo 'checked ="checked"' ; ?>  />
  <font color="white">    Female </font><input type="radio" value="Female" name="gender" id="gender"
 <?php  if ($_POST ['gender']=='Female') echo 'checked ="checked"' ; ?>  />
  </td>
     
  <td> <font color="white"> Course  </font> </td>    <td> </td>
  <td>
       <select name="course" id="course">
<option value="Bachelor of Science in Computer Science">
Bachelor of Science in Computer Science</option>
<option value="Bachelor of Science in Information Technology">
Bachelor of Science in Information Technology</option>
<option value="Bachelor of Science in Information System">
Bachelor of Science in Information System </option>
 <option value="Bachelor of Science in Information Management">
 Bachelor of Science in Information Management </option>
 <option value="Bachelor of Science in Software Engineering">
 Bachelor of Science in Software Engineering </option>
 <option value="Bachelor of Science in Accountancy">
 Bachelor of Science in Accountancy </option>
 <option value="Bachelor of Science in Management Accounting">
 Bachelor of Science in Management Accounting </option>
 <option value="Bachelor of Science in Management ">
 Bachelor of Science in Management </option>
 <option value="Bachelor of Science in Management Accounting">
 Bachelor of Science in Management Accounting </option>
  <option value="Bachelor of Science in Banking and Finance">
 Bachelor of Science in Banking and Finance</option>
 <option value="Bachelor of Science in Computer Engineering">
 Bachelor of Science in Computer Engineering</option>
 <option value="Bachelor of Science in Chemical Engineering">
 Bachelor of Science in Chemical Engineering</option>
 <option value="Bachelor of Science in Civil Engineering">
 Bachelor of Science in Civil Engineering</option>
 <option value="Bachelor of Science in Industrial Engineering">
 Bachelor of Science in Industrial Engineering</option>
 <option value="Bachelor of Science in Nursing">
 Bachelor of Science in Nursing</option>
 <option value="Bachelor of Science in Pharmacy">
 Bachelor of Science in Pharmacy</option>
 <option value="Bachelor of Science in Medical Technology">
 Bachelor of Science in Medical Technology</option>
</select> 
<script type="text/javascript">
  document.getElementById('course').value = "<?php echo $_POST['course'];?>";
</script>

   </td>                    

  </tr> 
      <tr><td><font color="white">Number of Units </font> </td>  <td> </td> <td>
 <input type="text" name="units"  value="<?php echo $units; ?> " size="30" /></td> 
        <td ><font color="white">Cost Per Unit </font></td>  <td> </td> <td >
<input type="text" name="cost"  value="<?php echo $cost; ?> "  size="30" /></td>                                                                            
                        
 </tr> 
 <tr><td><font color="white">Tuition Fee </font> </td>  <td> </td> <td>
 <input type="text" name="fee"  value="<?php echo $total_cost; ?> " size="30" /></td> 
        <td ><font color="white">Amount Paid </font> </td>  <td> </td> <td >
<input type="text" name="paid"  value="<?php echo $paid2; ?> " size="30" /></td>                                                                            
                        
 </tr> 
 <tr><td><font color="white">Change  </font> </td>  <td> </td> <td>
 <input type="text" name="change2"  value="<?php echo $change; ?> " size="30" /></td> 
 </tr>
 <tr><td colspan="2" align="center"><input type="submit" name="compute" value="Solve Tuition"
    title="Click here to compute the tuition fee of the student." />

<td colspan="2" align="center"><input type="submit" name="change" value="Solve Change"
    title="Click here to compute the payment of the student." />
<td colspan="2" align="center"><input type="submit" name="clear" value="Clear Textbox"
    title="Click here to clear the text box." />
</td>
</tr>
<?php
 error_reporting(0);

$fname = trim($_REQUEST['fname']);
$lname = trim($_REQUEST['lname']);
$gender = $_POST['gender'];
$course = $_POST['course'];


$units= trim($_REQUEST['units']);

$cost = trim($_REQUEST['cost']);
$paid2 = trim($_REQUEST['paid']); 

$paid = number_format($paid2,2,'.',',');

$solve = ($units * $cost);

$total_cost = number_format($solve,2,'.',',');

// Clear the text field

if ($_REQUEST['clear']){
   $fname="";
   $lname="";
   $gender="";
   $total_cost="";
   $course="";
   $units="";
   $cost="";
   $paid2="";
   
     
}

if ($_REQUEST['change']){

$change3 = ($paid2 - $solve);
$change =number_format($change3,2,'.',',');
}


?>
<tr><td><font color="white">  Name           : <?php echo  ucwords($fname) . " " . ucwords($lname); ?>  </font> </td> </tr>
<tr><td><font color="white">  Gender         : <?php echo trim($gender) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Course         : <?php echo trim($course) ?>  </font> </td> </tr>
 <tr><td><font color="white"> No. of Units   : <?php echo trim($units) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Cost Per Unit  : $<?php echo trim($cost) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Tuition Fee    : $<?php echo trim($total_cost) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Amount Paid    : $<?php echo trim($paid2) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Change         : $<?php echo trim($change) ?>  </font> </td> </tr>
 </table> 
 </fieldset>
</font>
 </form>     
 </body> 
 </html>