Monthly Archives: July 2016

SQL HAVING Clause

Hi Guys,
This SQL article explain how to use the SQL HAVING clause with example and syntax. Mainly the SQL HAVING clause is used in combination with the GROUP BY clause to restrict the groups of returned rows to only those whose the condition is TRUE.

Syntax


SELECT exp1, exp2, ... expn,
aggregate_function (aggregate_exp)
FROM tables
[WHERE conditions]
GROUP BY exp1, exp2, ... expn
HAVING condition;




Description

  • exp1, exp2, … expn:Expressions that are not encapsulated within an aggregate function.
  • aggregate_function: Aggregate functions in HTML5 are: SUM, COUNT, MIN, MAX, or AVG functions.
  • aggregate_exp:This is the column or expression that the aggregate_function will be used on.



  • tables:The tables that you wish to retrieve records from.
  • WHERE conditions:Fetch the data from table based on conditions. These are the conditions for the records to be selected.
  • HAVING condition:This is a further condition applied only to the aggregated results to restrict the groups of returned rows.

SQL HAVING Clause Example

We use HAVING Clause in SQL with different SQL aggregate functions.

1)Example – Using SUM aggregate function

In here, the HAVING clause explain with SUM aggregate functions in SQL.


SELECT name, SUM (salary)
FROM employee_details
GROUP BY name
HAVING SUM (salary) > 35000




The output like this:

name salary
Pritty 55000
Prince 45000
Princy 70000

2)Example – Using COUNT aggregate function


SELECT dept, COUNT(*) AS " Total Number of employees"
FROM employee_details
WHERE salary > 35000
GROUP BY dept
HAVING COUNT(*) > 10;




If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Form Validations with Pattern Matching – HTML5

Good Morning To all,
In the above article we have the basic idea related to server side form validation. Now we focus the client side form validation in php code. In the server side form validation developed by using Jvascript or Jquery method. But in the Client Side Validation method no jQuery or JavaScript needed. The pattern is new attributes in HTML5.

Syntax





Description

regularexpression: Specifies a regular expression that the <input> element’s value is checked against.

We Will See The Following:

  1. letters only
  2. numbers only
  3. email
  4. URL
  5. phone no
  6. alphanumeric




Letters

The pattern=”[A-Z]+” accept only capital letters. And also pattern=”[a-z]+”accept only small letters.
Combine capital and small letter with pattern=”[A-Za-z]+” method in HTML.


Numbers

pattern=”[0-9]+” accepts only numbers 0, 1, 2,3,4,5,6,7,8,9





E-Mail

pattern=”[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$” accepts valid email address. And we also use input type=”email” in HTML5.





URL

In input type=”url and pattern=”https?://.”” accept only valid url like http://….


Phone Number

Accept onlynumeric characters and specify the number limit. Specify the phone number upto the limit these limit and numbers are specify in pattern.
Also inputtype=”tel” in HTML5.





Alpha Numeric

Specify the alphanumeric characters.


Full Code




Server Side Form validations Using PHP




HTML5 Form Validations with Pattern Matching




If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Server Side Form Validations using PHP

Hi all,
In this article we will learn How to Validate Forms Using PHP. The server side form validation is very secure and useful in php code. We implement the form validation in php for registration to site or signup something like that. In the form validation, check input given by the user is correct or wrong. We check some useful form validation like:



  • Numbers only
  • Characters only
  • Email Address
  • Empty value
  • Input Length

demo

Numbers Only

In form validation, is_numeric() helps to check input given by the user is only numbers or not. First we save the user input value to a variable. After that, we check the input values are numbers or not. If the enter values in not number then errror message will display.





OR


In here we can add only numbers




Characters Only

In form validation, ctype_alpha() helps to check input given by the user is only letters or not. First we save the user input value to a variable. After that, we check the input values are letters or not. If the enter values is not characters then errror message will display.


OR





Email Address

Check the input email address are valid or not. If the enter email address is not valid email then error message will display.


OR




Empty Value

Check input value is empty or not. The empty() function helps to check the field is empty or not.





Input Length

The strlen() helps to calculate string length in PHP.


Full Code



Server Side Form validations Using PHP-Prittytimes





  
        

Form validation

/>
/>
/>
/>




If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

How to Delete Data from MySQL with Confirmation in PHP

Good Moring to all,
All are familure with how to delete data from databse using php page. But nobody try to develope delete data from mysql database with confirmation.
In here, now we discuss how to delete data from mysql database with confirmation in PHP.. We solve this problem with simple step in same page.

In the previous article shows how to insert the data to mysql database. For delete operation we use the existing database and table. for perform this operations, first we select data from mysql database.




Select Data From Database

First we fetch the data to php page from mysql database. I hope you know very well that how to select data from database , so i come to the point. First of all select the data from database table and display it on page.

0)
 {
  while($rowdata=mysqli_fetch_row($result_section))
  {
   ?>
            
First Name Last Name City Delete
No Datas Existing !!





delete_1

From the above code, first we include database connection to php page. And then select all the datas from ‘tbl_users’ table. Then display the datas into table field.

Delete data From MYSQL database with Confirmation

We already fetch the data from MYSQL database and display into table. And we just add the delete button into table with actions.

    Delete




We add one column in existing table for delete operation. In here, we click the button or image then call the javascript function delete_id.
And pass the database fiels id to function. In function the confirmation will occur and if the confirmation is true then the action is performed like as follows.


delete_2



Full code





PHP Delete Data With Javascript Confirmation 





    

    0)
 {
  while($rowdata=mysqli_fetch_row($result_section))
  {
   ?>
            
First Name Last Name City Delete
Delete
No datas existing !!!




If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Basic File Uploading Using PHP

Hi Guys,
In this article we are going to move How to upload the file using PHP. File uploading is mainly done to website like recruting sites, online applications etc. In recrutment site, the user upload their biodata, photo are uploaded through frond end and in here it connect to database also. But now we focus only how to upload the file to specific folder in php. The file uploading is very simple and easy to understand the process in php.

Table Of content

  1. The HTML
  2. The PHP




For uploading a file to specific folder contain only two part: html and php.

The HTML

The HTML parts are used in here for specify form,input and submit button in html for uploading operations. We use enctype=”multipart/form-data”helps to upload files in php. And input type=”file” to specify the type of input tag.



File Uploading To Specified Folder


  1. Method=”POST” : it should be POST.
  2. enctype=”multipart/form-data” : it’s specify content-type to be uploaded.



  3. type=”file” : attribute of the input tag shows input field as a file selector with a “Browse” Button.

The PHP

In php part,


	
	
	 
  1. $folder: Specify directory for uploading files. In here uploaded_files is the folder to upload file in php.
  2. move_uploaded_files : php function that moves selected file to the specified folder.

Full Code





	
	
	 


File Uploading To Specified Folder





If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Data Insert Into MySQL Database – PHP

Hi all,
In here, I will show you to how to insert data into mysql database from php page.

Table Of Content

  1. Create Database
  2. Create Table
  3. HTML Form
  4. HTML Style

insert_values



Create Database

In here, the database is create for performing insert operation. Create database and name it whatever you want.


CREATE DATABASE `prittytimes` ;




In here ‘prittytimes’ is the database name for creating table. We create table in prittytimes database.

Create Table

Now create table and name it ‘tbl_users’

CREATE TABLE `prittytimes`.`tbl_users` (
`user_id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`firstname` VARCHAR( 25 ) NOT NULL ,
`lastname` VARCHAR( 25 ) NOT NULL ,
`useremail` VARCHAR( 45 ) NOT NULL
) ENGINE = InnoDB;

We create ‘tbl_users’ table in ‘prittytimes’ database. And the tbl_users’ fields are user_id,firstname,lastname,useremail.

HTML Form

html form that inserts user first name , last name and email




HTML Style

HTMl page style is specified in style tag.


Full Code


  
  
  
  




PHP Data Insert Into MySql






From the above code we can clearly say that, first we specify the html part for input field like firstname, lastname,useremail. The fields are specified in input tag with name. Next is PHP part, in here first we specify database connection in php page for insert the value from form. Get the input values from form using $_POST[]method. and insert values to database from form field.

Happy coding

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Operators in PHP

Hi Guys,
Today we discuss operators in php. The operators are in PHP helps to perform different functionalities in php. It is mainly used to perform operations in values and variables. An operator is one type symbol, that is used to perform certain operations on its operands. Operator is always associate with operand.




Example

x+y

Here x and y are the operand and ‘+’ is the operator

In PHP language supports following type of operators.

  1. Arithmetic Operators
  2. Logical Operators
  3. Conditional Operators
  4. Comparison Operators
  5. Assignment Operators

1) Arithmetic Operator




In php the arithmetic operator helps to perform common arithmetic operation like addition, multiplication, division etc. In other words, it performs mathematical operations on its operands.

Operator Purpose Example
+ Perform addition of two operands. $x=10; $y=2; $z=$x+$y;
$z=12
Perform substraction of two operands. $x=10; $y=2; $z=$x-$y;
$z=8
* Perform multiplication of two operands. $x=10; $y=2; $z=$x*$y;
$z=20
/ Perform divide left operand by the right operand $x=10; $y=2; $z=$x/$y;
$z=5
% Divide left operand by the right operand and return remainder of division $x=11; $y=2; $z=$x/$y;
$z=5
++ Increment Operator, increase the integer values by 1. $x=10; $x++ will give 11
Decrement Operator, decrease the integer values by 1. $x=10; $x– will give 9




2) Logical Operators

It helps to perform logical operations on its operands.

Operator Purpose Example
&& If both the operands are non zero then condition becomes true. $x=true;$y=false;$z=$x && $y;
$z=false;
|| If any of the two operands are non zero then condition becomes true. $x=true;$y=false;$z=$x || $y;
$z=true;
! If a condition is true then Logical NOT operator will make false. $x=true; !($z=$x);
$z=false;

3) Conditional or Ternary Operator

There is one more operator called conditional operator. This first evaluates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation.




Operator Purpose Example
? : It is used for conditional expression. If Condition is true ? Then value X : Otherwise value Y

4) Comparison Operator

It helps you to perform comparision betweeen two operands.

Operator Purpose Example
== Checks if the value of two operands are equal or not, if yes then condition becomes true. (x == y) is not true.
!= Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (x != y) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (x > y) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (x < y) is true
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (x >= y) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (x <= y) is true

5) Assignment Operator

It allows you to assign value of one variable to another variable.




Operator Purpose Example
= Simple assignment operator, Assigns values from right side operands to left side operand z = x + y will assign value of x + y into z
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand z += x is equivalent to z = z + x
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand z -= x is equivalent to z = z – x
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand z *= x is equivalent to z = z * x
/= In here, it divides left operand with the right operand and assign the result to left operand z /= x is equivalent to z = z / x
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand z %= x is equivalent to z = z % x

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

How to Print backgroound image or color in PHP or HTML

Good Morning to all,
After a long time we discuss one useful topics in PHP also in HTMl. It’s very helpful for developers in web development. Everyone familure with print() in PHP and HTML. But nobody try to print background image or color in html page. Print particular div in print screen is very easy. But nobody knows how to implement background image in print screen using HTML or PHP. All are familure @media print in css. The @media print in css, helps to specify the style in print screen.



Print Example :




	
	Image Painting
	



Testing For print Screeen in HTML

Print




In the above code we can’t view the background image in print screen. Next we try to solve this problem.
We can specify the styles in print screen using style tage.

Print backgroound image or color in PHP or HTML

Next we move to one important topic related to print background image or color in print screen using PHP or HTML.




	
	Image Painting
	



Testing For print Screeen in HTML

<
Print

In the above code, print() will helps to print html data from page. We can print the data from current page.
We can specify the styles in print screen using style tage.
The -webkit-print-color-adjust:exact; helps to view the backgroound image in print screen.

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Decision Making Statement – PHP

Good morning to all,
The decision making statments helps in php to take some decisions in php script. It allows you to make decisions based upon the result of a conditions. Decision making statments allows you to control excecution, certain part of the php code. PHP support following conditional statment:

  • if statments
  • if…else statments
  • if..elseif.. else statments



  • Nested if statment
  • Switch statments

1. The if Statement

The syntax of the if statement is something like this:


if(condition){
true statement;
}
next statment;




In the if statement, first check if the condition is true or not. If the condition is true then excecute true staments and next staments. If the condition is false, then the true statement is not working, directly go to next statement

Example:

	

2. The if…else Statement

The syntax of the if statement is something like this:


if(condition)
{
true stament;
}
else
{
false stament;
}




In the if… else statment,first check the condition. First check, if the condition is true or not, if the condition is true,then excecutes the if condition part. Otherwise else part will excecutes.

Example

	

3. if..elseif.. else statments

The syntax of the if.. elseif…else statement is something like this:






if (condition) {
statement 1 excecute if the condition is true;
} elseif (condition) {
statement 2 executed if this condition is true;
} else {
statement 3 executed if all conditions are false;
}

In the if…elseif… else statement, first check the condition. First check,if the condition is true or not. If the condition is true, then excecute the if condition statment. If the condition is false, then go to else if staments. Check the condition in elseif statement. If the condition is true,then excecute the statment.Otherwise go to else statment.

4. Nested if statments

The syntax of the nested if statement is something like this:


if(outercondition)
{
if(innercondition)
{
true statement
}
else
{
false statments
}
}
else
{
False Statement
}

4. Switch statments

The syntax of the switch statement is something like this:






switch (n1) {
case 1:
code to be executed if n1=1;
break;
case 2:
code to be executed if n1=2;
break;
case 3:
code to be executed if n1=3;
break;
...
default:
code to be executed if n1 is different from all labels;
}

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.