Thursday, May 4, 2017

Multi Level User Login And Registration System in PHP and MySQL

Here is a sample program that I wrote using PHP and MySQL that allows the user to login in different user levels or rules in the system. The code is very compatible with PHP 7 database connections and queries.  I hope you will find my work useful. Thank you very much.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.













Sample Program Output



Program Listing

/* Written By: Mr. Jake Rodriguez Pomperada, MAED-IT             */
/* Tools : PHP / MySQL                                                                    */
/* May 4, 2017   Thursday                                                                */
/* jakerpomperada@yahoo.com and jakerpomperada@gmail.com */


connect.php

<?php
$username="root";  
$password="";  
$hostname = "localhost";  
//connection string with database  
$dbhandle = mysqli_connect($hostname, $username, $password)  
or die("Unable to connect to MySQL");  
echo "";  
// connect with database  
$selected = mysqli_select_db($dbhandle, "levels")  
or die("Could not select examples");  

?>


index.php

<?php include("header.php"); ?>
  <body>
    <div class="container">    
        <div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">                    
            <div class="panel panel-info" >
                    <div class="panel-heading">
                        <div class="panel-title">Login Security Page</div>
                      
                    </div>     

                    <div style="padding-top:30px" class="panel-body" >

                        <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
                            
                        <form action="login_action.php" method="post">
                                    
                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                        <input id="login-username" type="text" class="form-control" name="username" value="" placeholder="username">                                        
                                    </div>
                                
                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                                        <input id="login-password" type="password" class="form-control" name="password" placeholder="password">
                                    </div>

                                <div style="margin-top:10px" class="form-group">
                                    <!-- Button -->

                                    <div class="col-sm-12 controls">
                                
<input type="button" class="btn btn-success pull-right" style='margin-left:25px' 
 value="Register"  title="Click here to register to the system." onclick="location.href = 'register.php';">            
 <button type="submit" class="btn btn-success pull-right" title="Click here to Login in the system." >
 <span class="glyphicon glyphicon-check"></span> Login</button>
    
                                     
  </div>
</div>
</form>
                         </div>
</div>
</div> 
</div> <!-- /container -->

    <script src="js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>


login_action.php

<?php
include("connect.php"); 
$tbl_name="user_levels"; 

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

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($dbhandle,$username);
$password = mysqli_real_escape_string($dbhandle,$password);

$result = mysqli_query($dbhandle, "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password'");

if(mysqli_num_rows($result) != 1){
echo "<script>alert(' Wrong Username or Password Access Denied !!! Try Again');
window.location='index.php';
</script>";
}else{
$row = mysqli_fetch_assoc($result);
if($row['userlevel'] == 1){
header('location: admin.php');
}else if($row['userlevel'] == 2 ){
header("Location: faculty.php");
}else if($row['userlevel'] == 3 ){
header("Location: student.php");
}
else if($row['userlevel'] == 4 ){
    header("Location: staff.php");
}
else{
echo "<script>alert('Wrong Username or Password Access Denied !!! Try Again');
window.location='index.php';
</script>";
}
}

?>


insert.php


<?php

include("connect.php"); 
$tbl_name="user_levels"; 

$username=$_POST['username']; 
$password=$_POST['password']; 
$user_level = $_POST['user_level']; 

$result = mysqli_query($dbhandle, "INSERT INTO $tbl_name (username,password,userlevel) VALUES ('$username','$password','$user_level')");


if($result===TRUE)
{
echo "<script>alert('User Account has been saved in the database.');
window.location='index.php';
</script>";
}
else
{
  echo"The query did not run";
mysqli_close($result);


?>

register.php

<html>
 <?php include("header.php"); ?>
  <body>
    <div class="container">    
        <div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">                    
            <div class="panel panel-info" >
                    <div class="panel-heading">
                        <div class="panel-title">Registration Page</div>
                      
                    </div>     

                    <div style="padding-top:30px" class="panel-body" >

                        <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
                            
                        <form action="insert.php" method="post">
                                    
                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                        <input id="login-username" type="text" class="form-control" name="username" value="" placeholder="username"  autofocus required>                                        
                                    </div>
                                
                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                                        <input id="login-password" type="password" class="form-control" name="password" placeholder="password" required>
                                    </div>
 <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                        <input id="login-user_level" type="text" class="form-control" name="user_level" placeholder="user level" required>
                                    </div>

                                <div style="margin-top:10px" class="form-group">
                                    <!-- Button -->

                                    <div class="col-sm-12 controls">
                                
<input type="button" class="btn btn-success pull-right" style='margin-left:25px' value="Cancel" 
title="Click to return to main page." onclick="location.href = 'index.php';">            
 <button type="submit" class="btn btn-success pull-right" title="Click here to save the records in the database." >
 <span class="glyphicon glyphicon-check"></span> Ok</button>
    
                                     
  </div>
</div>
</form>
                         </div>
</div>
</div> 
</div> <!-- /container -->


 </html>

header.php

<?php include("connect.php"); ?>
<!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">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">
    <title>User - Levels</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="signin.css" rel="stylesheet">
    <script src="js/ie-emulation-modes-warning.js"></script>

  </head>

  admin.php

  <html>
  <head>
    <title> Administrator Page </title>
 <head>
  <style>
    body {
 font-family:arial;
 background-color : lightblue;
 color:red;
};
</style>
<body><br>
 <h1 align="center">
  Welcome To Administrator Page 
  </h1>
 </body>
 </html>

 faculty.php

 <html>
  <head>
    <title> Administrator Page </title>
 <head>
  <style>
    body {
 font-family:arial;
 background-color : lightblue;
 color:red;
};
</style>
<body><br>
 <h1 align="center">
  Welcome To Administrator Page 
  </h1>
 </body>
 </html>

 student.php

 <html>
  <head>
    <title> Student Page </title>
 <head>
  <style>
    body {
 font-family:arial;
 background-color : yellow;
 color:blue;
};
</style>
<body><br>
 <h1 align="center">
  Welcome To Student Page 
  </h1>
 </body>
 </html>

 staff.php

 <html>
  <head>
    <title> Staff Page </title>
 <head>
  <style>
    body {
 font-family:arial;
 background-color : pink;
 color:yellow;
};
</style>
<body><br>
 <h1 align="center">
  Welcome To Staff Page 
  </h1>
 </body>
 </html>


user_levels.sql

-- phpMyAdmin SQL Dump
-- version 4.6.5.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: May 03, 2017 at 01:52 PM
-- Server version: 10.1.21-MariaDB
-- PHP Version: 7.0.15

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

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

--
-- Table structure for table `user_levels`
--

CREATE TABLE `user_levels` (
  `id` int(11) NOT NULL,
  `username` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  `userlevel` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `user_levels`
--

INSERT INTO `user_levels` (`id`, `username`, `password`, `userlevel`) VALUES
(1, 'user1', 'user1', '1'),
(2, 'user2', 'user2', '2'),
(3, 'user3', 'user3', '3'),
(4, 'user4', 'user4', '4'),
(5, 'admin', 'admin', '1'),
(6, 'a', 'a', '1'),
(8, 'adam', 'adam', '2'),
(9, 'jake', 'jake', '3'),
(10, 'jacob', 'jacob', '2'),
(11, 'mark', 'mark', '4'),
(12, 'jose', 'jose', '2'),
(13, 'mario', 'mario', '2');

--
-- Indexes for dumped tables
--

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

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `user_levels`
--
ALTER TABLE `user_levels`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
/*!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, May 1, 2017

Word Count in Visual Basic NET

In this article I would like to share with you a sample program that will ask the user to give a sentence or string and then our program will count the number of words in the given word or sentence using Microsoft Visual Basic NET.  The source code is very short and very easy to understand.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Listing


Program Listing

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim strInput As String
        strInput = TextBox1.Text
        Dim strSplit() As String
        strSplit = strInput.Split(CChar(" "))
        Label2.Text = "Number of words: " & strSplit.Length
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        Label2.Text = ""
        TextBox1.Focus()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        End
    End Sub
End Class



Sunday, April 30, 2017

Decimal To Roman Numeral in Visual Basic NET

Here is a sample program to ask the user to give a number and then it will convert in Roman Numeral equivalent using Microsoft Visual Basic NET.  The code is very short and easy to understand. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


Public Class Form1
    Private Function ConvertRoman(ByVal n As Integer) As String
        If n = 0 Then ConvertRoman = "0" : Exit Function
        Const r = "IVXLCDM"
        Dim i As Integer = Math.Abs(n)
        Dim s As String = ""

        For p As Integer = 1 To 5 Step 2
            Dim d As Integer = i Mod 10
            i = i \ 10
            Select Case d '
                Case 0 To 3 : s = s.PadLeft(d + Len(s), Mid(r, p, 1))
                Case 4 : s = Mid(r, p, 2) & s
                Case 5 To 8 : s = Mid(r, p + 1, 1) & s.PadLeft(d - 5 + Len(s), Mid(r, p, 1))
                Case 9 : s = Mid(r, p, 1) & Mid(r, p + 2, 1) & s
            End Select
        Next

        s = s.PadLeft(i + Len(s), "M")
        If n < 0 Then s = "-" & s
        ConvertRoman = s
    End Function
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label2.Text = " The equivalent value of " & TextBox1.Text & " is " & ConvertRoman(TextBox1.Text) & "."
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        Label2.Text = ""
        TextBox1.Focus()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        End
    End Sub
End Class




Decimal To Roman Numeral in Visual Basic 6

Here is a sample program that will ask the user to give a number and then it will be converted into roman numeral value using Visual Basic 6.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

Public Function ConvertRoman(ByVal n As Integer) As String
   If n = 0 Then FormatRoman = "0": Exit Function
    
   Const r = "IVXLCDM"
   Dim i As Integer: i = Abs(n)
   Dim s As String, p As Integer
   For p = 1 To 5 Step 2
      Dim d As Integer: d = i Mod 10: i = i \ 10
      Select Case d
         Case 0 To 3: s = String(d, Mid(r, p, 1)) & s
         Case 4:      s = Mid(r, p, 2) & s
         Case 5 To 8: s = Mid(r, p + 1, 1) & String(d - 5, Mid(r, p, 1)) & s
         Case 9:      s = Mid(r, p, 1) & Mid(r, p + 2, 1) & s
         End Select
      Next
   s = String(i, "M") & s
   If n < 0 Then s = "-" & s
   ConvertRoman = s
   End Function


Private Sub Command1_Click()
Label2.Caption = "The equivalent value of " & Text1.Text & " is " & ConvertRoman(Text1.Text) & "."
End Sub

Private Sub Command2_Click()
End
End Sub



Wednesday, April 26, 2017

Leap Year Checker Using Two Dimensional Array in C++

Here is a sample program that I wrote a very long time ago while I am teaching in one of the university in Bacolod City, Negros Occidental Philippines in my C++ class. This program will ask the user to give a series of years and then our program will check if the given year is a leap year or not using two dimensional array.  I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler in this sample program. I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Program Listing

#include <iostream>

using namespace std;


 main()
{

int years[2][2];

  cout << "\n\n\t\t\t LEAP YEAR LISTER 1.O";
  cout << "\n\t Created By: Mr. Jake Rodriguez Pomperada,MAED-IT";
  cout << "\n\n";
for (int row=0; row <2; row++) {
    for (int col=0; col <2; col++) {
        cout << "Enter Year :=> ";
        cin >> years[row][col];
    }
}
cout << "\n\n";
// Leap Year
cout << "LIST OF LEAP YEAR";
cout << "\n\n";
for (int row=0; row <2; row++) {
    for (int col=0; col <2; col++) {

if (years[row][col]%4==0)
{
cout << " " << years[row][col] << " ";
}

    }
}

cout << "\n\n";
// not a leap year
cout << "LIST OF NOT A LEAP YEAR";
cout << "\n\n";
for (int row=0; row <2; row++) {
    for (int col=0; col <2; col++) {
        if (years[row][col]%4==0)
{

}
  else {
      cout << " " << years[row][col] << " ";
    }
  }
}
cout << "\n\n";
system("PAUSE");
}


Occurrence of a Number in C++

Here is a sample program that I wrote a very long time ago while I am teaching in one of the university in Bacolod City, Negros Occidental Philippines in my C++ class. This program will count the occurrence of the number.  I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler in this sample program. I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



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

Divide Two Numbers in Turbo Pascal

Here is a sample program that will ask the user to give two numbers and then our program will compute for it's quotient. I am using a user defined function in Turbo Pascal. I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

Program divide_two_numbers;
Uses Crt;

Var c,d,results : real;


Function Divide(a,b : real) : real;
begin
  divide := (a/b);
end;

Begin
  Clrscr;
  Writeln;
  textcolor(White);
  Write('Divide Two Numbers in Turbo Pascal');
  Writeln;
  Writeln;
  Write('Enter First Number  : ');
  Readln(c);
  Writeln;
  Write('Enter Second Number : ');
  Readln(d);

  results := Divide(c,d);

  Writeln;
  Writeln;
  Write('The quotient of ',c:5:2, ' and ',d:5:2, ' is ' ,results:5:2, '.');
  Writeln;
  Writeln;
  Write('End of Program');
  Writeln;
  Readln;
End.



Upper Case String Converter in Turbo Pascal

Here is a sample program that I wrote using Turbo Pascal 6 For DOS to ask the users name and then our program will convert the given users name into upper case letters. The code is very easy to understand and use. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

Program Upper_Case_Convert;
Uses Crt;

Var User_Name,Result : String;


Function StringUpper(s:String):String; 
var 
i:byte; 
begin 
  for i:=1 to length(s) do s[i]:=Upcase(s[i]); 
  StringUpper := s; 
end; 

Begin
  Clrscr;
  Writeln;
  textcolor(White);
  Write('Upper Case Converter in Turbo Pascal');
  Writeln;
  Writeln;
  Write('Enter you Name : ');
  Readln(User_Name);

  Result := StringUpper(User_Name);

  Writeln;
  Writeln;
  Write(' Hello ' ,Result,'.');
  Writeln;
  Writeln;
  Write('End of Program');
  Writeln;
  Readln;
End.




Area of the Square in Visual Foxpro


Here is a sample program that will ask the user to give a length of the side of the square and then the program will compute for the area of the square. I wrote this sample program using Microsoft Visual Foxpro 5.0. I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output



Program Listing


Ok Button   Command1  Click

set decimal to 2
SET FIXED ON

clear

side = val(thisform.text1.value) 
area_square = (side * side);

final_solve= round(area_square,2)

thisform.label4.caption = "The area of the square is " + alltrim(thisform.text3.value)


thisform.text3.value =  final_solve

Clear Button  Command2  Click

thisform.text1.value=""
thisform.text3.value=""
thisform.text1.setfocus
thisform.label4.caption =""


Quit Button Command2  Click

Quit