Monthly Archives: December 2015

WordPress Redirect Https To Http With Htaccess

Hi all,
Nobody know how to redirect a https: request to http:// using .htaccess in wordpress, today I share some information related to this problem.




You can redirect all website pages from https to http. It will be redirect only when you open the page with https.

First write your code in .htaccess file, after first check few URLs to see if it’s even necessary. If your code is perfectly working then you can implement this code into your work.
For Example, try to request your site url using https// prefix and see what happens. If your site automatically redirect to http:// version of the page, then your code is perfectly working and good.





See Example Below
https://prittytimes.com Redirect to http://prittytimes.com
https://prittytimes.com/page1/ Redirect to http://prittytimes.com/page1/
https://prittytimes.com/page2/ Redirect to http://prittytimes.com/page2/





Open .htaccess in root folder
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Replace with Following code
RewriteEngine On

RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]




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

Fetch MYSQL table data – PHP

Welcome to all,
Here we discuss one useful topic related to MYSQL,fetch the data from data base in MySQL using PHP.
From the MYSQL database the data can be fetched by executing SQL SELECT statement through PHP function mysql_query. The mysqli_fetch_array() or mysql_fetch_array() function is most frequently option. This function returns row as an associative array, a numeric array, or both. This function returns FALSE if there are no more rows.



The basic syntax of the SELECT query can be given with:

SELECT column_name(s) FROM table_name

Basic Content

  • mysql_connect() : Used to open connection in MySQL
  • mysql_error() : this returns the text of the error message from previous MySQL operation and empty string if no error occurred.
  • mysql_select_db() : Sets the current active database on the server which is associated with specified link identifier returned by mysql_connect().



  • mysqli_query() : This sends a query to current active database on the server. It takes SQL query as parameter.
  • mysqli_fetch_array():The mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both.

Below is a simple example to fetch records from Employee_table table.

There are three steps in here. First create Employee_table in fetch_demo database. Second, insert the data to the Employee_table and last fetch the data from Employee_table.

Create Employee_table

CREATE TABLE Employee_table
(Employee_ID INTEGER PRIMARY KEY,
Employee_First_Name CHAR(200),
Employee_Last_Name CHAR(200),
Employee_Email_ID CHAR(100)
);




Insert the data to Employee_table

INSERT INTO Employee_table(Employee_ID,Employee_First_Name,Employee_Last_Name,Employee_Email_ID) VALUES (01, ‘Priya’, ‘Mary’,’priyamary@gmail.com’);
INSERT INTO Employee_table(Employee_ID,Employee_First_Name,Employee_Last_Name,Employee_Email_ID) VALUES (02, ‘Princy’, ‘Mary’,’princymary@gmail.com’);
INSERT INTO Employee_table(Employee_ID,Employee_First_Name,Employee_Last_Name,Employee_Email_ID) VALUES (03, ‘Preethi’, ‘Sunny’,’preethi_sunny@gmail.com’);
INSERT INTO Employee_table(Employee_ID,Employee_First_Name,Employee_Last_Name,Employee_Email_ID) VALUES (04, ‘Pritty’, ‘Mary’,’prittyamaryvarghese@gmail.com’);

Fetch the data from Employee_table

       0)
			{
				echo "";
				echo "";
                echo "";
                echo "";
                echo "";
                echo "";
				echo "";
				while($row = mysqli_fetch_array($result))
				{
					echo "";
					echo "";
					echo "";
					echo "";
					echo "";
					echo "";
				}
				echo "
Employee_IDEmployee_First_NameEmployee_Last_NameEmployee_Email_ID
" . $row['Employee_Id'] . "" . $row['Employee_First_Name'] . "" . $row['Employee_Last_Name'] . "" . $row['Employee_Email_ID'] . "
"; } else { echo "No records matching your query were found."; } } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($con); } mysqli_close($con); ?>

Fetch all the data from Employee_table. And display in table. Fetch the data out of the fetch_demo database.
There are several mathods are available in fetching data from MYSQL database. In above example mysql_fetch_array() function is used.

The Output like:




Employee_ID Employee_First_Name Employee_Last_Name Employee_Email_ID
01 Priya Mary priyamary@gmail.com
02 Princy Mary princymary@gmail.com
03 Preethi Sunny preethi_sunny@gmail.com
04 Pritty Mary prittyamaryvarghese@gmail.com

All the datas are fetched from table Employee_table. There are four fields are available, they are:Employee_ID,Employee_First_Name,Employee_Last_Name,Employee_Email_ID.
Fetched datas are displayed in table.

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

mysql_connect() and mysql_pconnect()

Hi all,
Nobody knows what are the main differnce between MYSQL_CONNECT() and MYSQL_PCONNECT(). MYSQL_CONNECT() and MYSQL_PCONNECT() are working for database connection. But these two have some little diffrence. In mysql_pconnect(), ‘p’ stands for persistance connection.



The mysqli_connect() function opens a new connection to the MySQL server. Every time it is opening and closing the database connection, depending on the request .

SYNTAX

mysqli_connect(host,username,password,dbname,port,socket);

Mysql_pconnect checks if that if the same host, username and password connection is already opened an identifier for it will be returned instead of making a new connection. mysql_pconncet() is useful when you have a lot of traffice on your site




Difference between mysql_connect() and mysql_pconnect()

MYSQL_CONNECT()

  • mysql_connect can be used to close the connection.Every time it is opening and closing the database connection, depending on the request .
  • Here database is opened everytime when the page is loaded in MYSQL connect



  • When the page is loaded, the database is loaded everytime
  • It is used to close the connection
  • Example:<
    ?php
    $conn = mysql_connect(‘host’, ‘mysql_user’, ‘mysql_password’);
    if (!$conn)
    {
    die(‘Could not connect: ‘ . mysql_error());
    }
    echo ‘Connected successfully’;
    mysql_close($conn);
    ?>
    Description:

    • host: Specifies a host name or an IP address like localhost.
    • mysql_user: Specifies the MySQL username
    • mysql_password: Specifies the MySQL password

MYSQL_PCONNECT()




  • We use the mysql_pconncet(), it initially tries to find an open persistent connection.
  • The mysql_pconncet() opens persistant connection
  • The mysql_pconnect() does not support the close connection
  • mysql_pconnect() cannot close the connection. Here open a persistant connection to the database



  • Here database need not be connected everytime.
  • The database need not be connected every time in mysql_pconncet().

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

SQL LIKE Operator

Good morning to all,
Welcome to SQL commnands, queries, operators etc. Now we are discuss the SQL LIKE operator. The LIKE operators used to fetch the data from database foor specific pattern.




The LIKE operator is used to search for a specified pattern in a column used in WHERE clause. There are two wildcards used in conjunction with the LIKE operator:

  • The percent sign (%)- represents zero, one or more than one character.
  • The underscore (_)-represents only one character

SQL LIKE SYNTAX




SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;

The Basic Syntax of % and _ is as follows:

SELECT FROM table_name
WHERE column LIKE ‘YYYY%’

or

SELECT FROM table_name
WHERE column LIKE ‘%YYYY’

or

SELECT FROM table_name
WHERE column LIKE ‘%YYYY%’

or

SELECT FROM table_name
WHERE column LIKE ‘YYYY_’




or

SELECT FROM table_name
WHERE column LIKE ‘_YYYY’

or

SELECT FROM table_name
WHERE column LIKE ‘_YYYY_’

You can combine N number of conditions using AND or OR operators. Here, YYYY could be any numeric or string value.

Here are number of examples showing WHERE part having different LIKE clause with ‘%’ and ‘_’ operators




Statement Description
WHERE MARK LIKE ‘500%’ Finds any values that start with 500
WHERE MARK LIKE ‘%500%’ Finds any values that have 500 in any position
WHERE MARK LIKE ‘_00%’ Finds any values that have 00 in the second and third positions
WHERE MARK LIKE ‘5_%_%’ Finds any values that start with 5 and are at least 3 characters in length
WHERE MARK LIKE ‘%5’ Finds any values that end with 5
WHERE MARK LIKE ‘_2%3’ Finds any values that have a 2 in the second position and end with a 3
WHERE MARK LIKE ‘2___3’ Finds any values in a five-digit number that start with 2 and end with 3

Example of LIKE clause

Consider Employee table

Employee_ID Name Salary
101 Adam 15000
102 Alex 18000
103 Abhi 17000

Example 1: SELECT * from Employee where Name like ‘A%’;

The above query will return all records where Name starts with character ‘A’ from Employee table.



Employee_ID Name Salary
101 Adam 15000
102 Alex 18000
103 Abhi 17000

Example2: SELECT * from Employee where Name like ‘_d%’;

The above query will return all records from Employee table where Name contain ‘d’ as second character.

Employee_ID Name Salary
101 Adam 15000

Example 3: SELECT * from Employee where Name like ‘%x’;

The above query will return all records from Employee table where Name contain ‘x’ as last character.

Employee_ID Name Salary
102 Alex 18000




Example4: SELECT * from Employee where Name like ‘%d%’;

The above query will return all records from Employee table where Name contain ‘d’ as second character.

Employee_ID Name Salary
101 Adam 15000




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

Save the particular div in PDF format onclick – Jquery

Here I’m going to discuss about how to save or download the particular div as in the PDF format onclick using jsPDF jquery file. This is very simple and most interesting useful tutorial

I already showed you one tutorial to Save the HTML or PHP webpage as PDF using JAVASCRIPT here for the particular div




Table of Content

  • HTML
  • JQUERY AND SCRIPT

demo

The HTML Code

			


// Content goes here, for pdf format

Jquery And Script

		
		
		
	




Download Code




download




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

Retype password Validation – Javascript

Hi Guys,
Here I explain, how to check Password and Confirm Password validation for Password TextBox using pur javascript method with demo.
The Password and Confirm password are in textboxes. And these are compared using JavaScript and if the values do not match an error message will occur like password must be same. If the values match then display the sucess message like ‘you are valid user Thanks for visiting our site. We can performe these operations by pure php code or javascript with jquery also.



In password validation, the table of contents are:

  • The HTML
  • The JavaScript

The HTML

The two input text boxes are specified within the form tag. Also the function all specifie in HTML. The function call in form tag on page submit, using onsubmit nethod.




Password:
Re-enter Password:

The JavaScript

Here, check the password and confirm password are correct using function. If password and confirm password are not matched then the error message will display.




demo

Full Code







Password:
Re-enter Password:




The Action perform on form submit. Call the testpass() function at onsumit event handler. When the Button is clicked, the Validate JavaScript function gets executed.

Inside the Validate JavaScript function(testpass()), the values of the Password and the Confirm Password TextBoxes are fetched and are compared. If the values do not match an error message will occur using JavaScript alert message box and false value is returned in order to stop the form submission otherwise the success message is displayed using javascript alert message box.




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

Reset Auto-Increment – MySQL

Good morning to all,
Here I going to demonstrate how to reset auto-increment value in MySql. Assign to auto-increment attributes to a column of a table, to generate unique identity for the new row. If new row is inserted it incrementsthe value one.

Whenever you insert a new row into a table, MySQL automatically assigns a sequence number to the auto-increment column. For example, if the table has 5 rows and you insert a new row without specifying the value for the auto-increment column, MySQL will automatically inserts a new row with id value 6.




Some times you want to reset auto-increment value in mysql, first create table and insert the values to database after that we try to reset the AUTO-INCREMENT values in mysql.

	CREATE TABLE Employee_table (
		Employee_Id int(11) NOT NULL AUTO_INCREMENT,
		Employee_Name varchar(200) DEFAULT NULL,
		Employee_Age int(3),PRIMARY KEY (id)
	);




Insert some sample data into Employee_table.

INSERT INTO Employee_table(Employee_Name,Employee_Age)
			VALUES('Ammu',24),
			('Appu',21),
			('Achu',45);

Now Employee_table is created and three rows inserted into it.

The table like:

select * from Employee_table;

Employee_Id Employee_Name Employee_Age
1 Ammu 24
2 Appu 21
3 Achu 45




Let’s check Delete all the records in Employee_table.

delete FROM Employee_table

After delete all the data from Emplyee_table, now if you insert any new value it auto-increment the value to 4. For solving this problem we reset the auto-increment values in mysql

How to Reset Auto-Increment In MySql

To reset the auto-increment values in mysql table using three method. They are:

  • Method 1: Alter Command
  • Method 2: Truncate
  • Method 3: DROP TABLE and CREATE TABLE statements.

Method 1: Alter Command

To reset MySql Auto-increment through Alter Command.

ALTER TABLE Employee_table AUTO_INCREMENT = 1;

It resets the auto-increment value to 1. So can specify any other value as well.

Method 2: Truncate

The TRUNCATE TABLE statement removes all the data of a table and reset auto-increment value to zero.




truncate table Employee_table

Method 3: DROP TABLE and CREATE TABLE statements

DROP TABLE and CREATE TABLE to reset the auto-increment column

DROP TABLE table_name;
CREATE TABLE table_name(…);

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

SQL JOINS

Hi all,
The SQL joins are used for combine rows from two or more table based on a common field between them.We are discuss this topic today. It fetch data from two or more tables and which is joined to appear as single set of data. Join Keyword is used in SQL queries for joining two or more tables. Minimum required condition for joining table, is (n-1) where n, is number of tables.



Different types of JOINs are available in SQL .They are:

  • INNER JOIN
  • LEFT JOIN



  • RIGHT JOIN
  • FULL JOIN

1) INNER Join or EQUI Join

The INNER JOIN selects all rows from both tablesresults based on the match between the columns in both tables. Returns all the rows when there is atleast one matches in both tables.




SYNTAX

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

or

SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;

inner_join

Example of INNER JOIN. The Employee1 table




Employee_ID Employee_Name
1 Jose
2 Thomas
3 Joseph

The Employee2 table





Employee_ID Salary
1 4000
2 8000


Inner JOIN query will be,

SELECT * from Employee1, Employee2 where Employee1.Employee_ID = Employee2.Employee_ID;

The result will be

Employee_ID Employee_Name Employee_ID Salary
1 Jose 1 4000
2 Thomas 2 8000

2) LEFT Join

Return all rows from the left table, and the matched rows from the right table.

SYNTAX

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;

or

SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;

left_join

Example of LEFT JOIN. The Employee1 table




Employee_ID Employee_Name
1 Jose
2 Thomas
3 Joseph

The Employee2 table

Employee_ID Salary
1 4000
2 8000

LEFT JOIN query will be,

SELECT Employee_ID, Employee_Name,Salary
FROM Employee1
LEFT JOIN Employee2
ON Employee1.Employee_ID = Employee2.Employee_ID;

The result will be

Employee_ID Employee_Name Salary
1 Jose 4000
2 Thomas 8000
3 Joseph NULL

The LEFT JOIN keyword returns all rows from the left table (Employee1), with the matching rows in the right table (Employee2).




3) RIGHT Join

The right join return all rows from the right table, and the matched rows from the left table.

SYNTAX

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;

or

SELECT column_name(s)
FROM table1
RIGHT OUTER JOIN table2
ON table1.column_name=table2.column_name;

right_join

Example of RIGHT JOIN. The Employee1 table



Employee_ID Employee_Name
1 Jose
2 Thomas
3 Joseph

The Employee2 table

Employee_ID Salary
1 4000
2 8000

RIGHT JOIN query will be,

SELECT Employee_ID, Employee_Name,Salary
FROM Employee1
RIGHT JOIN Employee2
ON Employee1.Employee_ID = Employee2.Employee_ID;

The result will be




Employee_ID Employee_Name Salary
1 Jose 4000
2 Thomas 8000

The RIGHT JOIN keyword returns all rows from the right table (Employee2), with the matching rows in the left table (Employee1).




4) FULL OUTER Join

Return all the rows from the left table and right table

SYNTAX

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;

full_join

Example of FULL OUTER JOIN. The Employee1 table




Employee_ID Employee_Name
1 Jose
2 Thomas
3 Joseph

The Employee2 table

Employee_ID Salary
1 4000
2 8000

RIGHT JOIN query will be,

SELECT Employee_Name,Salary
FROM Employee1
FULL OUTER JOIN Employee2
ON Employee1.Employee_ID = Employee2.Employee_ID;

The result will be




Employee_Name Salary
Jose 4000
Thomas 8000
Joseph

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

Truncate, Drop and Rename a Table- SQL

Hi all,
Here I share some useful information in sql queries like truncate command, drop command alter command. These is more helpful in MYSQL operations.

For delete complete data from an existing table using TRUNCATE command. And also delete the data inside the table.




For delete a table using DROP command. It helps to remove all table definition and all data, indexes of the corresponding table.

For rename the table by using rename command.

TRUNCATE COMMAND





The SQL truncate command is used for delete all the data from an existing table. TRUNCATE table is similar to DELETE command in sql with no where clause.

SYNTAX

TRUNCATE TABLE table_name

Here is an Example explaining it.

truncate table Employee;

The above query will delete all the records of Employee table. Delete complete data from Employee table.





DROP COMMAND

The SQL DROP command is used for completely removes a table from database. This command also destroy the table struncture also. It is used to remove a table definition and all data, indexes, triggers, constraints, and permission specifications for that table.

SYNTAX

drop table table_name




Here is an Example explaining it.

drop table Employee;

The above query will delete the Employee table completely. The drop helps to remove all the employee table data.

The DROP command can also be used on Databases.

SYNTAX

drop database database_name;

Here is an Example explaining it.

drop database Organization;

The above query will drop a database named Organization from the system.




RENAME COMMAND

The rename command is used to rename a table.

SYNTAX

rename table old-table-name to new-table-name

old-table-name:Specifies the name of the table to be renamed.

new-table-name:Specifies the new name of the table.




Here is an Example explaining it.

rename table Employee to Employee_details;

The above query will rename Employee table to Employee_details. The old table name is Emplyess rename as new table name Employee_details

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