Friday, November 3, 2017

XYZ Chat System Using PHP and MySQL


Communication is one of the most aspect of our human life as we are born in this world. We have learned how to communicate by gestures, hand signal and the language that is being taught to us by our parents.  There are thousands of languages and dialects all over the world that makes communication with other people more difficult and needs most of the time a translator just to translate one language to another language. One of the official language the is being spoke by millions of people around the world is the English language. The language itself is very universal the most text books and novels are being written using the English language.

Because of our shrinking world now a day’s communication becomes more easier compared to the past. I still remember during my early age my parents teach us how to write a letter and drop the letter to the post office. That’s the time the Internet is not widely used nor not yet existing in our country here in the Philippines.  By mid 1990’s the introduction of the Internet in our society paved way to a new method of communication the use of email, chat, text, voice over IP and video conferencing becomes a common medium of communication among us. It makes our communication to our friends, family members and relatives more efficient and best of all cost less. The interaction is in real time so there’s no need for us to wait for weeks or months just to receive the reply letter or message.

In this article I will teach you and discuss how to make a chat system using PHP and MySQL. When I have learned how to use mIRC, Yahoo Messenger and more recently chat system in Facebook I have also some questions in my mind how to create my own chat system. As I said before the use of Internet as source of information is very common now a days and very beneficial after some research I find some codes and try to improve and add functionality the is suited in my needs. That’s I came out with the program called XYZ Chat System 1.0 Using PHP and MySQL.  In writing the code I started with the use of HTML,CSS for the framework and layout of my page. After that I use JQuery  to refresh my page is every 1 second and finally the use of PHP and MySQL to save the messages in our database.

What the program will do is very simple I will ask the user to enter the name of the person below is a text field where all the conversation will be display to the end user and finally a text file where the user type the message and by clicking the send message it will display the message of the screen and save the message including the name of the sender in our MySQL database so we can monitor and retrieve whatever conversation that our user has in our system. This program is very simple there are still many things that can be done just to improve its overall functionality in general.

I test the chat system in my localhost it means in one computer and a LAN network. If you like to test this program in a LAN network my advice is for your mapped first the server computer and assign its IP address and for the of the client computer you also assigned a different IP address for example let say the server IP address is 192.168.20.10 when we access our program via the web browser we can use a command like this http://192.168.20.10/chat/index.php as simple with this command we can access of chat system that is being mapped in our windows operating system.

I am currently accepting programming 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.









Sample Program Output


Here is the complete program listing of XYZ Chat System 1.0 Using PHP and MySQL

index.php

<?php
session_start();
if(isset($_POST['submit']))
{
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("chat", $con);
                                $message=$_POST['message'];
                                $sender=$_POST['sender'];
                                mysql_query("INSERT INTO message(message, sender)VALUES('$message', '$sender')");
}

?>
<!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>XYZ Chat System 1.0</title>
<script language="javascript" src="jquery-1.2.6.min.js"></script>
<script language="javascript" src="jquery.timers-1.0.0.js"></script>
<script type="text/javascript">

$(document).ready(function(){
   var j = jQuery.noConflict();
                j(document).ready(function()
                {
                                j(".refresh").everyTime(1000,function(i){
                                                j.ajax({
                                                  url: "refresh.php",
                                                  cache: false,
                                                  success: function(html){
                                                                j(".refresh").html(html);
                                                  }
                                                })
                                })
                               
                });
               
   j('.refresh').css({color:"red"});
});
</script>
<style type="text/css">
.refresh {
    border: 1px solid black;
                border-left: 4px solid black;
    color: green;
    font-family: tahoma;
    font-size: 12px;
    height: 225px;
    overflow: auto;
    width: 400px;
                padding:10px;
                background-color:#FFFFFF;
}
#post_button{
                border: 1px solid #3366FF;
                background-color:#3366FF;
                width: 100px;
                color:#FFFFFF;
                font-weight: bold;
                margin-left: -105px; padding-top: 4px; padding-bottom: 4px;
                cursor:pointer;
}
#textb{
                border: 1px solid black;
                border-left: 4px solid black;
                width: 320px;
                margin-top: 10px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; width: 415px;
}
#texta{
                border: 2px solid black;
                border-left: 4px solid black;
                width: 410px;
                margin-bottom: 10px;
                padding:5px;
}
p{
border-top: 1px solid #EEEEEE;
margin-top: 0px; margin-bottom: 5px; padding-top: 5px;
}
span{
                font-size:12;
                font-weight: bold;
                color: green;
}
</style>
</head>
<body bgcolor="lightgreen">
<font face="comic sans ms">
<h1> <center> XYZ Chat System 1.0 </center> </h1> </font>
<br>
<form method="POST" name="" action="">
<input name="sender" type="text" id="texta"  value="<?php echo $sender ?>"/>
<div class="refresh">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("chat", $con);
$result = mysql_query("SELECT * FROM message ORDER BY id DESC");
while($row = mysql_fetch_array($result))
  {
  echo '<p>'.'<span>'.$row['sender'].'</span>'. '&nbsp;&nbsp;' . $row['message'].'</p>';
  }

mysql_close($con);
?>
</div>
<input name="message" type="text" id="textb"/>
<input name="submit" type="submit" value="Send Message" id="post_button" />
</form>
</body>
</html>

Here is the code that will refresh all the conversations of the user in chat system
refresh.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("chat", $con);
$result = mysql_query("SELECT * FROM message ORDER BY id DESC");
while($row = mysql_fetch_array($result))
  {
  echo '<p>'.'<span>'.$row['sender'].'</span>'. '&nbsp;&nbsp;' . $row['message'].'</p>';
  }
mysql_close($con);
?>

chat.sql

-- phpMyAdmin SQL Dump
-- version 3.1.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 01, 2014 at 03: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: `chat`
--

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

--
-- Table structure for table `message`
--

CREATE TABLE IF NOT EXISTS `message` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `message` text NOT NULL,
  `sender` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

--
-- Dumping data for table `message`
--

INSERT INTO `message` (`id`, `message`, `sender`) VALUES
(2, 'Welcome to our school Maria?', 'Mario'),
(3, 'Thank you Mario for the warm accommodation.', 'Maria'),
(4, 'What are your subject this semester?', 'Mario'),
(5, 'My subjects are Science, Math, English and Accounting.', 'Maria'),
(6, 'See you in school Maria God Bless you always.', 'Mario'),
(7, 'Thanks and Take care always.', 'Maria'),
(8, 'good bye maria', 'Mario'),
(9, 'Thank you Mario I hope we can me friends', 'Maria'),
(11, 'Good bye', 'Maria');



Total Days To Year, Weeks and Days Converter in C++

In this article I would like to share with you a sample program that will ask the user to give the total number of days and then our program will count the number of years, weeks and days on the given total days using C++ as our programming language.

I am currently accepting programming 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.






Sample Program Output


Program Listing

#include <iostream>

using namespace std;

int main()
{
    int no_days=0, years=0, weeks=0,days=0;

    cout << "\t Total Days To Year, Weeks and Days Converter in C++";
    cout << "\n\n";
    cout << "Created By Mr. Jake R. Pomperada, MAED-IT";
    cout << "\n\n";
    cout << "How many total days : ";
    cin >> no_days;

    years = (no_days/365);
    weeks = (no_days % 365) / 7;
    days  = (no_days % 365) % 7;

    cout << "\n\n";
    cout << no_days << " Days " << years << " year(s) "
         << weeks << " weeks "<< days  << " days " << ".";
    cout << "\n\n";
    cout << "End of Program.";
    cout << "\n\n";

}


Thursday, November 2, 2017

Employee's Information System in C++

Here is a very simple employee's information system that I wrote using C++ in a very long time ago when I am still teaching in the University here in my hometown in Bacolod City. I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler in writing this simple program using struct as my data structure.

I am currently accepting programming 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 <iostream>
#include <iomanip>

using namespace std;


  struct emp  {
      string name;
      int age;
      float salary;
  };

  main() {
      emp users[3];
        cout << "\t Employees Information System";
      cout << "\n\n";
      for (int x=0; x<3; x+=1) {
       cin.ignore();
       cout << "Enter your name  :";
       getline(cin,users[x].name);

       cout << "Enter your age    :";
       cin >> users[x].age;
       cout << "Enter your salary :";
       cin >> users[x].salary;
      }
  cout << "\n\n";
      cout << "\t List of Employees";
      cout << "\n\n";
      for (int x=0; x<3; x+=1) {
      cout << setprecision(2) << fixed;
      cout   << "\n" << setw(5) << users[x].name
          << setw(10) << users[x].age
          << setw(15) << users[x].salary;
      }
      cout << "\n\n";
      system("pause");
  }


Product of Two Numbers Using Function in C++

A very simple program that I wrote that will ask the user to give two numbers and then our program will compute the product using function in C++. The code is very simple and easy to understand it also shows you how to use one dimensional array in C++.

I am currently accepting programming 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 <iostream>
 #include <iomanip>

  using namespace std;

 // Global variable

  int val[2],product=0;

   void accept() {
       cout << "Enter two numbers : ";
       cin >> val[0] >> val[1];
   }

   int solve(int a, int b)
    {
     return(a*b);
    }

    void display()
    {

       cout << setw(50) <<"The product is "
            << solve(val[0],val[1])
            << ".";
    cout << "\n\n";
    system("pause");
    }

main() {
    accept();
    display();
}

Number Occurrence in C++

In this article I would like to share with you a sample program that I wrote in C++ a long time ago to count the number of occurrence of the given number by the user.

I am currently accepting programming 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 <iostream>

using namespace std;


main(void) {
 int items[5];
    int search=0;
    int occur=0,x=0;


    for (int x=0; x<5; x++) {
        cout << "Enter Item No."
            << x+1 << " : ";
        cin >> x[items];
    }

     cout << "\n\n";
     cout <<"Enter Item to search :";
     cin >> search;
    for (x=0; x<5; x++) {
     if (search == x[items]) {
         occur++;

     }

    }
 cout << "\n\n";
     cout << "Number occurence of is "
         << occur << ".";




     if (search != x[items]) {
         cout << "Not Found in the List.";

     }


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

Person Record System in Codeigniter

In this article I would like to share with you the work of my good friend and fellow software engineer Jai Soni from India a simple Person Record System in Codeigniter which allows the user to add, edit and delete persons information in the database. I am very thankful that Jai share his work us.

I am currently accepting programming 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.







Sample Program Output







Saturday, October 28, 2017

Number of Days Before Christmas Counter in JavaScript

Here is a sample program that I wrote that will count the number of days before Christmas using JavaScript.

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.



Sample Program Output


Program Listing

<html>
<title>  Number of Days Before Christmas in JavaScript </title>
<body>
<style>
body {
 font-family:arial;
 font-size:50px;
 font-weight:bold;
 color:blue;
 background-color:lightgreen;
}
</style>
<br>
<h4> Number of Days Before Christmas in JavaScript </h4>
<script>
var day_description = "Christmas";
var day_before = "Christmas Eve";

var today = new Date();
var year = today.getYear();
if ((navigator.appName == "Microsoft Internet Explorer") && (year < 2000))
year="19" + year;
if (navigator.appName == "Netscape")
year=1900 + year;
var date = new Date("December 25, " + year);
var diff = date.getTime() - today.getTime();
var days = Math.floor(diff / (1000 * 60 * 60 * 24));

if (days > 1)
document.write("There are " + (days+1) + " days until " + day_description + "!");
else if (days == 1)
document.write("Tommorrow is " + day_before  + "!");
else if (days == 0)
document.write("Today is " + day_before + "!");
else if (days == -1)
document.write("It's " + day_description + "!");
else if (days < -1)
document.write(day_description + " was " + ((days+1)*-1) + (days < -2 ? " days" : " day") + " ago this year!");

</script>
</body></html>

Current Day in JavaScript

A very simple script that I wrote using JavaScript to display the current day based on the date of your computer.

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.



Sample Program Output


Program Listing

<html>
<title> Current Date in JavaScript </title>
<body>
<style>
body {
 font-family:arial;
 font-size:50px;
 font-weight:bold;
 color:blue;
 background-color:lightgreen;
}
</style>
<br><br>
<script>
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)    
year = year + 1900; 
document.write("Today is " + lmonth + " ");
document.write(date + ", " + year );
</script>
</body></html>

Sorting Techniques in Turbo Basic

Here is a program that I wrote way back in 1998 it is BASIC program to demonstrate the different sorting techniques I use Turbo Basic in writing this program.

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


REM NAME OF PROJECT : SORTING TECHNIQUES
REM DATE FINISHED   : SEPTEMBER 19, 1998
REM AUTHOR          : JAKE R. POMPERADA
CLS
100
COLOR 10
PRINT
PRINT
FOR C = 1 TO 28
PRINT CHR$(205);
NEXT C
PRINT
print TAB(5) " SORTING TECHNIQUES"
PRINT TAB(8) " MAIN MENU "
FOR C = 1 TO 28
PRINT CHR$(205);
NEXT C
COLOR 11
PRINT
PRINT
PRINT " [1] System Date & Time "
PRINT " [2] Bubble Sort "
Print " [3] Insertion Sort"
PRINT " [4] Selection Sort "
PRINT " [5] Quicksort"
PRINT " [6] Mergesort "
PRINT " [7] Quit / Exit Program"
PRINT " "
FOR C = 1 TO 28
PRINT Chr$(205);
NEXT C
print
input "Enter Your Choice => ",a

IF ( A > 7 OR A < 1) THEN GOTO 105

IF A = 1 THEN
 CLS
 GOTO 110
 END IF

IF A = 2 THEN
  CLS
  GOTO 210
  END IF

IF A = 3 THEN
  CLS
  GOTO 310
  END IF

IF A = 4 THEN
  CLS
  GOTO 410
  END IF

IF A = 5 THEN
  CLS
  GOTO 510
  END IF

IF A = 6 THEN
  CLS
  GOTO 610
  END IF


IF A = 7 THEN
  CLS
 FOR C = 1 TO 75
 PRINT CHR$(205);
 delay .03
 NEXT C
 LOCATE 3,28:  Print "Exit Program To DOS..."
 LOCATE 5,29:  Print "Designed By: Servo"
 FOR C = 1 TO 75
 PRINT CHR$(205);
 delay .03
 NEXT C
 REM  THE KEYWORD SYSTEM EXIT PROGRAM TO DOS !!!
 SYSTEM
 END IF


105
PRINT
FOR C = 1 TO 75
PRINT CHR$(205);
NEXT C
color 31
LOCATE 20,29: PRINT "Invalid Option !!!"
LOCATE 21,23: PRINT "Choose Only Options [1/2/3/4/5/6/7]"
BEEP
FOR C = 1 TO 75
color 11
PRINT CHR$(205);
NEXT C
DELAY 1.5
CLS
GOTO 100

110
CLS
FOR C = 1 TO 28
PRINT CHR$(205);
NEXT C
print
PRINT TAB(3) "SYSTEM DATE AND TIME :"
FOR C = 1 TO 28
PRINT CHR$(205);
NEXT C
print
print
COLOR 15
PRINT "Date :" ,Date$
PRINT "Time :" ,Time$
DELAY 3
CLS
GOTO 100

210
REM BUBBLE SORT MODULE
CLS
DIM A(100)
COLOR 15
FOR F = 1 TO 20
PRINT "=";
NEXT F
PRINT
PRINT " BUBBLE SORT MODULE"
FOR G = 1 TO 20
PRINT "=";
NEXT G
PRINT
PRINT
Input "How many inputs :",A
FOR I = 1 To A
PRINT "Item #";i;
INPUT A(i)
NEXT I
Let N = I - 1
For J = 1 To N - 1
For I = 1 To N-J
If a(i) <= A(i+1) then 270
Let T=A(I)
Let A(i)=A(i+1)
Let A(i+1)=T
270 Next I
Next J
print
print " Sorted List of";a; "items"
PRINT
For I = 1 To N
Print a(i)" ";
next I
delay 3
cls
goto 100
end

310
REM INSERTION SORT MODULE
CLS
Dim B(100)
COLOR 15
FOR F = 1 TO 22
PRINT "=";
NEXT F
PRINT
PRINT "INSERTION SORT MODULE"
FOR F = 1 TO 22
PRINT "=";
NEXT F
PRINT
PRINT
Input "How many inputs :",a
for i = 1 To a
print "Item #";i;
input B(i)
next i
Let N = I - 1
For I = 1 To N - 1
Let J = I
Let T = B(I+1)
540 If J < 1 then 590
IF T >= B(J) THEN 590
Let B(J+1)=B(J)
Let J = J -1
Goto 540
590 Let B(J+1)=T
Next I
Print
print " Sorted List of";a; "items"
PRINT
For I = 1 To N
Print B(i)" ";
NEXT I
DELAY 3
CLS
GOTO 100
END

410
REM SELECTION SORT MODULE
CLS
DIM L(100)
COLOR 15
FOR F = 1 TO 23
PRINT "=";
NEXT F
PRINT
PRINT "SELECTION SORT MODULE"
FOR F = 1 TO 23
PRINT "=";
NEXT F
PRINT
PRINT
Input "How many inputs :",a
for i = 1 To a
print "Item #";i;
input L(i)
next i
Let N = I - 1
FOR I = 1 TO N - 1
FOR J = I + 1 TO N
IF L(J) >= L(I) THEN 330
LET Q = L(J)
LET L(J)=L(I)
LET L(I) = Q
330 NEXT J
NEXT I
PRINT
PRINT " Sorted List of";a; "items"
PRINT
For I = 1 To N
PRINT L(i)" ";
NEXT I
delay 3
cls
GOTO 100
END

510
REM QUICKSORT MODULE
CLS
Dim S(100)
COLOR 15
FOR F = 1 TO 22
PRINT "=";
NEXT F
PRINT
PRINT TAB(3) "QUICKSORT MODULE"
FOR F = 1 TO 22
PRINT "=";
NEXT F
PRINT
PRINT

PRINT "How many inputs :";
INPUT V
for R = 1 To V
print "Item #";R;
INPUT S(R)
next R
for O = 1 TO V - 1
FOR I = O + 1 TO V
IF  S(I) >=  S(O) THEN 130
LET C = S(O)
LET S(O) = S(I)
LET S(I) = C
130 NEXT I
    NEXT O
PRINT
PRINT " Sorted List of";V "items"
PRINT
FOR F = 1 TO V
PRINT S(F);
NEXT F
delay 3
cls
GOTO 100
END

610
REM MERGESORT MODULE
CLS
DIM X(100)
COLOR 15
FOR F = 1 TO 20
PRINT "=";
NEXT F
PRINT
PRINT " MERGESORT MODULE"
FOR F = 1 TO 20
PRINT "=";
NEXT F
PRINT
PRINT
Input "How many inputs :",a
for i = 1 To A
PRINT "Item #";i;
INPUT X(i)
next i
LET N = I - 1
For J = 1 To N - 1
For I = 1 To N-J
If X(i) <= X(i+1) then 970
Let T=X(I)
LET X(i)=X(i+1)
LET X(i+1)=T
970 Next I
Next J
PRINT
PRINT " Sorted List of";a; "items"
PRINT
For I = 1 To N
PRINT X(I)" ";
NEXT I
DELAY 3
CLS
GOTO 100
END

1000 END