Thursday, 25 December 2014

Mail Function in PHP

mail.php

<?php
ob_start();



$email = trim($_GET['j_email']);


$support_address = "rajkumarsahoo@yahoo.com"; //Your Company Email ID//

$headers2 = "From: ".$support_address;

if ( $email == "" )

{
echo "Name is empty";
}
else
{

// Your Auto Replay Message//
mail($email,"Thank You For Contact ","Thank You We Will Contact You Shortly");
//unset($email);
echo "<script>
                                                          window.location.href = 'contact_full.php';
                                                          </script>";
}

?>

Create Process Bar Like Gmail In HTML

index.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>DEMO - Gmail like progress bar with CSS and jQuery</title>
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<style>
body {
background: rgb(245, 245, 245);
}

.g-div {
position: absolute;
top: calc(50% -   6px);
left: calc(50% -   160px);
text-align: center;
width: 320px;
font-weight: bold;
}

.loader-gmail {
padding: 1px;
overflow: hidden;
border: 1px solid #a4a4a4;
}

.progress {
width: 320px;
height: 8px;
background-image: linear-gradient(135deg, #6187f2 0%, #6187f2 25%, #5679da 25%, #5679da
50%, #6187f2 50%, #6187f2 75%, #5679da 75%, #5679da 100%);
background-repeat: repeat;
background-position: 0px 0px;
background-size: 16px 16px;
background-clip: content-box;
animation: loading 1s linear infinite;
-o-animation: loading 1s linear infinite;
-moz-animation: loading 1s linear infinite;
-webkit-animation: loading 1s linear infinite;
}

@keyframes loading {
    from {
      background-position:0px 0px;
    }
    to {
 background-position: -16px 0px;
    }
}
@-webkit-keyframes loading {
    from {
      background-position:0px 0px;
    }
    to {
 background-position: -16px 0px;
    }
}
@-moz-keyframes loading {
    from {
      background-position:0px 0px;
    }
    to {
 background-position: -16px 0px;
    }
}
@-o-keyframes loading {
    from {
      background-position:0px 0px;
    }
    to {
 background-position: -16px 0px;
    }
}
</style>

<script>
    var p=0;
    function timeout_trigger() {
  $(".progress").css("max-width",p+"%");
  $(".progress-view").text(p+"%");
  if(p!=100) {
  setTimeout('timeout_trigger()', 50);
  }
  p++;
}
    timeout_trigger();
  </script>
</head>
<body>
<div style="width:730px;margin:auto">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- demos -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-4537529140156254"
     data-ad-slot="4444050329"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>

<div class="g-div">
Loading <span class="progress-view">0%</span>
<div class="loader-gmail">
<div class="progress"></div>
</div>
</div>


</body>


</html>

Create Dynamic URL in jsp

1.index.jsp page

<html>
  <head>
    <title>the c:url action (1)</title>
  </head>
  <body>
    This page takes 3 values that you specify, and forwards them to another JSP.
    That JSP will create a URL to another page, that then extracts the
    parameters and displays them.
    <p />
      <form action="createURL.jsp" method="post">
        <table>
          <tr><td>Enter name:</td>
              <td><input type="text" name="name"   /></td></tr>
          <tr><td>Enter age:</td>
              <td><input type="text" name="age"    /></td></tr>
          <tr><td>Enter gender:</td >
              <td><input type="text" name="gender" /></td></tr>
        </table>
        <input type="submit" value="Submit details" />
      </form>
  </body>

</html>


2. createURL.jsp

<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>

<c:url value="displayValues.jsp" var="displayURL">
  <c:param name="nameParam"   value="${param.name}" />
  <c:param name="ageParam"    value="${param.age}" />
  <c:param name="genderParam" value="${param.gender}" />
</c:url>

<html>
  <head>
    <title>the c:url action (2)</title>
  </head>
  <body>
    This page receives the values you specified, and creates a URL that contains
    them.
    <p />
    The generated URL is <c:out value="${displayURL}" />. <p/>
    Click <a href='<c:out value="${displayURL}" />'>here</a> to view the it.
  </body>

</html>

3.displayValues.jsp

<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>

<html>
  <head>
    <title>the c:url action (3)</title>
  </head>
  <body>
    <h3>List of query string parameters:</h3>
    <ul>
      <c:forEach items="${param}" var="currentParam">
        <li><c:out value="${currentParam.key}" />
            = <c:out value="${currentParam.value}" /></li>
      </c:forEach>
    </ul>
 </body>
</html>

Friday, 14 November 2014

Create Trigger in MySql Database



Create Two Table

First Table : employees

 CREATE TABLE employees (
employeeNumber INT(11) ,
lastName VARCHAR(200),
firstName VARCHAR(200),
extension VARCHAR(200),
email VARCHAR(100),
officeCode VARCHAR(100),
reportsTo INT(11),
jobTitel VARCHAR(100)
 )

Insert value in the 1st table employees

insert  into `employees`(`employeeNumber`,`lastName`,`firstName`,`extension`,`email`,`officeCode`,`reportsTo`,`jobTitel`) values (1,'sahoo','Raj','120','raj@gmail.com','201200',22,'HR');


Second Table : employees

CREATE TABLE employees_audit (
    id INT(11) NOT NULL AUTO_INCREMENT,
    employeeNumber INT(11) NOT NULL,
    lastname VARCHAR(50) NOT NULL,
    changedon DATETIME DEFAULT NULL,
    ACTION VARCHAR(50) DEFAULT NULL,
    PRIMARY KEY (id)
 )

Update Trigger

Here we create a trigger before_employee_update.

when we update employees table it will automatically insert data into employees_audit on behave of
matching employeeNumber.

DELIMITER $$
CREATE TRIGGER before_employee_update
    BEFORE UPDATE ON employees
    FOR EACH ROW BEGIN
    INSERT INTO employees_audit
    SET ACTION = 'update',
     employeeNumber = OLD.employeeNumber,
        lastname = OLD.lastname,
       changedon = NOW();
END$$
DELIMITER ;

After create trigger we run this query

UPDATE employees SET lastName = 'Phan' WHERE employeeNumber = 1

It insert into employees_audit table.


Delete Trigger

Create a another table empsalary

CREATE TABLE `empsalary` (
  `employeeNumber` int(20) DEFAULT NULL,
  `salary` varchar(4000) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Create trigger delete_employees


DELIMITER $$
CREATE TRIGGER delete_employees
    AFTER DELETE ON employees
    FOR EACH ROW BEGIN

    DELETE FROM employees_audit
    WHERE employeeNumber = OLD.employeeNumber;
 
     DELETE FROM empsalary
    WHERE employeeNumber = OLD.employeeNumber;
     
END$$
DELIMITER ;

After create this trigger we run following command

DELETE FROM employees WHERE employeeNumber=1

It will delete records from three tables where employeeNumber=1


BEFORE INSERT TRIGGER

create trigger product_Trigger

CREATE TRIGGER product_Trigger BEFORE INSERT ON employees
FOR EACH ROW
UPDATE employees_audit SET lastname=New.lastName
WHERE employeeNumber=New.employeeNumber


After run this query you run following command

INSERT INTO employees(employeeNumber,lastName,firstName,extension,email,officeCode,reportsTo,jobTitel) VALUES(1,"amit",'kumar','samal','patta','0012',200,'fsf')

After run this command it insert these values into employees table and update employees_audit  table
set lastname=amit where it found employeeNumber is same that is 1.


AFTER INSERT TRIGGER

create trigger insert_multiple_tables

CREATE TRIGGER insert_multiple_tables AFTER INSERT ON employees
FOR EACH ROW
INSERT INTO employees_audit(employeeNumber,lastname,changedon)
VALUES(NEW.employeeNumber,NEW.lastName,NOW())

here your trigger is created

After run this command you run following command

INSERT INTO employees(employeeNumber,lastName,firstName,extension,email,officeCode,reportsTo,jobTitel) VALUES(10,"amitas",'kumar','samal','patta','0012',200,'fsf')

it insert the data into employees table and employees_audit table


Saturday, 23 August 2014

Difference between shallow copy and deep copy in java

A shallow copy would copy the object without any of its contents or data, In copied object all the variables are passed by reference from the original object.
Remeber that, In shallow copy, Copied object and Original object refer to the same data in memory.
Hence modifying the state of the original object would also modify the state of the copied object too.
By default, when you call the super.clone() method against an object, It would perform a shallow copy.

The second type of copy, Deep-copy copies the object including all the contents / states.
Hence each object refers to a different space in memory and modifying one object will not affect the other.
Remember that to make an exact copy of an object (deep copy), you must serialize the object.