Friday, 31 July 2015

How to COOKIE Example

<?php session_start(); ?>
<?php


  if(isset($_POST['txtname']) && isset($_POST['txtname']))
  {
    
              $username=$_POST['txtname'];
             $password=$_POST['txtpass'];
           
       
            if(isset($_POST['chlrember']) && $_POST['chlrember'] == 'on')
            {
   
                 setcookie('txtname',$username, time()+120);
                  setcookie('txtpass',$password, time()+120);
            }
            else { 
    //setcookie("txtname", $username, time()-120);
    //setcookie("txtpass", $password, time()-120);
          }
   
   
   
  } 
  else {
         
          $username = '';
          $password = '';
              if(isset($_COOKIE['txtname']))
                 { $username=$_COOKIE['txtname']; }
               
             if(isset($_COOKIE['txtpass']))
                { $password=$_COOKIE['txtpass'];  }
        }
   
 
 
 
   if(isset($_POST['btnlogin']))
   {
      if( $_POST['txtname']=='admin' &&  $_POST['txtpass']=='admin')
      {
         
         $_SESSION['my']=$_POST['txtname'];   
         header('location:list.php');   
       
      }
      else
      {
        echo "Wrong User name";
      }
     
   
   }

 
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
    <script type="text/javascript">
        function chkform(form)
        {
          if(form.txtname.value=="")
          {
         
           form.txtname.focus();
           document.getElementById("a1").innerHTML="Enter User Name";
           return false;
          }
          if(form.txtpass.value=="")
          {
                form.txtpass.focus();
                document.getElementById("a2").innerHTML="Enter Your Password";
                return false;
          }
          return true;
       
        }
    </script>
</head>


<body bgcolor="#999966">
<form name="lo1" method="post" onSubmit="return chkform(this)">
    <table>
         <tr>
            <tr>
                <th>User Name</th>
                <td><input type="text" name="txtname" placeholder="Enter User Name"  value="<?=$username;?>" ><span id="a1" style="color:red"></span></td>
               
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="password" name="txtpass" placeholder="Enter Pssword" value="<?=$password;?>" ><span id="a2" style="color:red"></span></td>
            </tr>
            <tr>
                <td colspan="2"><input type="checkbox" name="chlrember" > Remember Me</td>
                
            </tr>
            <tr>
                <td><input type="submit" name="btnlogin" value="Login"></td>
            </tr>
        </tr>
    </table>   
</form>

</body>
</html>

 

How To login Page With Remember me with COOKIE

<?php session_start(); ?>
<?php


  if(isset($_POST['txtname']) && isset($_POST['txtname']))
  {
    
              $username=$_POST['txtname'];
             $password=$_POST['txtpass'];
           
       
            if(isset($_POST['chlrember']) && $_POST['chlrember'] == 'on')
            {
   
                 setcookie('txtname',$username, time()+120);
                  setcookie('txtpass',$password, time()+120);
            }
            else { 
    //setcookie("txtname", $username, time()-120);
    //setcookie("txtpass", $password, time()-120);
          }
   
   
   
  } 
  else {
         
          $username = '';
          $password = '';
              if(isset($_COOKIE['txtname']))
                 { $username=$_COOKIE['txtname']; }
               
             if(isset($_COOKIE['txtpass']))
                { $password=$_COOKIE['txtpass'];  }
        }
   
 
 
 
   if(isset($_POST['btnlogin']))
   {
      if( $_POST['txtname']=='admin' &&  $_POST['txtpass']=='admin')
      {
         
         $_SESSION['my']=$_POST['txtname'];   
         header('location:list.php');   
       
      }
      else
      {
        echo "Wrong User name";
      }
     
   
   }

 
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
    <script type="text/javascript">
        function chkform(form)
        {
          if(form.txtname.value=="")
          {
         
           form.txtname.focus();
           document.getElementById("a1").innerHTML="Enter User Name";
           return false;
          }
          if(form.txtpass.value=="")
          {
                form.txtpass.focus();
                document.getElementById("a2").innerHTML="Enter Your Password";
                return false;
          }
          return true;
       
        }
    </script>
</head>


<body bgcolor="#999966">
<form name="lo1" method="post" onSubmit="return chkform(this)">
    <table>
         <tr>
            <tr>
                <th>User Name</th>
                <td><input type="text" name="txtname" placeholder="Enter User Name"  value="<?=$username;?>" ><span id="a1" style="color:red"></span></td>
               
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="password" name="txtpass" placeholder="Enter Pssword" value="<?=$password;?>" ><span id="a2" style="color:red"></span></td>
            </tr>
            <tr>
                <td colspan="2"><input type="checkbox" name="chlrember" > Remember Me</td>
                
            </tr>
            <tr>
                <td><input type="submit" name="btnlogin" value="Login"></td>
            </tr>
        </tr>
    </table>   
</form>

</body>
</html>

Thursday, 23 July 2015

How date regular expression in php validation

if(!preg_match('/^(19|20)\d\d[\-\/.](0[1-9]|1[012])[\-\/.](0[1-9]|[12][0-9]|3[01])$/',$txtstrtdate))
       {
           echo $error="In valid Date";
          $code="2";
       }

Wednesday, 22 July 2015

How To live Data Search with Ajax used LIKE Query

===================
list.php
===================

<script>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>

</head>

<body>
<form name="f11" method="post">
<div>
<span style="color:#FFF">Enter * All Data Show</span>&nbsp;&nbsp;&nbsp;<input type="text"  onchange="showUser(this.value)"/></div>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</form>
</body>
</html>
================
getuser.php
==============
<?php
include('connection.php');
$q =$_GET['q'];


?>
<!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>Untitled Document</title>
</head>

<body>
<?php

if($q=='*')
{
 $sql="select * from employee ";
}
else
{
 $sql="SELECT * FROM employee WHERE emp_name OR emaill OR emp_username LIKE '%$q%'
AND emp_name OR emaill OR emp_username LIKE '%$q%'";
}

$result = mysqli_query($dd,$sql);
 $n=mysqli_num_rows($result);
  if($n > 0)
  {
echo "<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>

</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['emp_name'] . "</td>";
    echo "<td>" . $row['emaill'] . "</td>";
    echo "<td>" . $row['emp_username'] . "</td>";
  
    echo "</tr>";
}
echo "</table>";
  } else { echo "Data Not Found"; }
?>
</body>
</html>

Monday, 20 July 2015

How to multiple Table Join Query

$sqlqr="select p.*,c.*,con.* from product as p LEFT JOIN categorie as c ON p.categaree=c.cat_id LEFT JOIN country as con ON p.conid=con.cid where usr_id=$id";

How to Dropdown country State Example

show-country-city-ajax.php
===============================
<?php
include('connection.php');
?>
<html>
<head>
<script>

function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get-data.php?q="+str,true);
//xmlhttp.open("GET","get-data1.php?yy="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

Select Your Country<select onChange="showUser(this.value)">
      <option>select</option>
<?php
$sql="SELECT * FROM country";
$result = mysqli_query($dd,$sql);
while($row = mysqli_fetch_array($result))
{
$id=$row['cid'];
echo "<option value='$id'>" . $row['coname'] . "</option>";
}
?>
</select>

<div id="txtHint" style="width:100px; border:0px solid gray;">
<b>your city disp here</b>
</div>

</body>
</html>

================
Get_data.php
===================

<?php
include('connection.php');
$q=$_GET["q"];
$sql="SELECT * FROM state WHERE conid ='$q'";
$result = mysqli_query($dd,$sql);
echo "Your State <select>";
while($row = mysqli_fetch_array($result))
{
    $id11=$row['stid'];
echo "<option>" . $row['stname'] . "</option>";
}

echo "</select>";
?>

===========
Note
===========
database
country filed  id and countryname
state filed Stid,Sname,cid(country table id)

How to user Name Chacked With Example

<?php

include('connection.php');
?>
<!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>Untitled Document</title>
<script type="text/javascript">
  function chk(form)
  {
      if(form.txtname.value=="")
    {
      form.txtname.focus();
      document.getElementById("a11").innerHTML="Blank not allow";
      return false;
    }
    var ar = document.getElementById("a1").value;
    if(ar=="true")
    {
   
    }
    else {
            return false;
    }
    return true;
  }
  function userchk(str)
  {
    if(window.XMLHttpRequest)
     {
       xmlhttp = new XMLHttpRequest();
     }
     xmlhttp.onreadystatechange = function()
     {
   
          if(xmlhttp.readyState==4 && xmlhttp.status==200)
          {
               document.getElementById("msg").innerHTML = xmlhttp.responseText;
            if(xmlhttp.responseText=="user name not valid")
            {
             
              document.getElementById("a1").value="false";
            }
            else {
               
                  document.getElementById("a1").value="true";
                }
           
           }
     }
     xmlhttp.open("GET","ajax1.php?id="+str,true);
     xmlhttp.send();
  }
</script>
</head>

<body>
   <form name="f1" method="post" onsubmit="return chk(this);">
           <input type="text" name="txtname" onBlur="userchk(this.value)" />
           <span id="msg"></span>
           <span id="a11"></span>
           <input type="hidden" name="a1" value="" id="a1"  />

        <input type="submit" name="btnadd"  />
   
   </form>
   <?php
     if(isset($_POST['btnadd']))
     {
        $txtname=$_POST['txtname'];
         $sql="insert into simple(uname) values('$txtname')";
         $sqlexc=mysqli_query($dd,$sql);
         if(!$sqlexc)
         {
           echo mysql_error();
         }
         else {
       
           echo "<script>alert(' insert data');</script>";
         }
     }
  
   ?>
</body>
</html>

Sunday, 19 July 2015

How to image progress display % in javascript

<style>
  #progress_bar {
    margin: 10px 0;
    padding: 3px;
    border: 1px solid #000;
    font-size: 14px;
    clear: both;
    opacity: 0;
    -moz-transition: opacity 1s linear;
    -o-transition: opacity 1s linear;
    -webkit-transition: opacity 1s linear;
  }
  #progress_bar.loading {
    opacity: 1.0;
  }
  #progress_bar .percent {
    background-color: #99ccff;
    height: auto;
    width: 0;
  }
</style>

<input type="file" id="files" name="file" />
<button onclick="abortRead();">Cancel read</button>
<div id="progress_bar" style="width:100%;"><div class="percent">0%</div></div>

<script>
  var reader;
  var progress = document.querySelector('.percent');

  function abortRead() {
    reader.abort();
  }

  function errorHandler(evt) {
    switch(evt.target.error.code) {
      case evt.target.error.NOT_FOUND_ERR:
        alert('File Not Found!');
        break;
      case evt.target.error.NOT_READABLE_ERR:
        alert('File is not readable');
        break;
      case evt.target.error.ABORT_ERR:
        break; // noop
      default:
        alert('An error occurred reading this file.');
    };
  }

  function updateProgress(evt) {
    // evt is an ProgressEvent.
    if (evt.lengthComputable) {
      var percentLoaded = Math.round((evt.loaded / evt.total) * 100);
      // Increase the progress bar length.
      if (percentLoaded < 100) {
        progress.style.width = percentLoaded + '%';
        progress.textContent = percentLoaded + '%';
      }
    }
  }

  function handleFileSelect(evt) {
    // Reset progress indicator on new file selection.
    progress.style.width = '0%';
    progress.textContent = '0%';

    reader = new FileReader();
    reader.onerror = errorHandler;
    reader.onprogress = updateProgress;
    reader.onabort = function(e) {
      alert('File read cancelled');
    };
    reader.onloadstart = function(e) {
      document.getElementById('progress_bar').className = 'loading';
    };
    reader.onload = function(e) {
      // Ensure that the progress bar displays 100% at the end.
      progress.style.width = '30%';
      progress.textContent = '100%';
      setTimeout("document.getElementById('progress_bar').className='';", 2000);
    }

    // Read in the image file as a binary string.
    reader.readAsBinaryString(evt.target.files[0]);
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

Friday, 17 July 2015

How to Two table Left Join Query Example

 
  $sql="se
lect p.*,c.* from product as p  LEFT JOIN categorie as c ON p.categaree=c.cat_id where usr_id=$id";

Friday, 10 July 2015

Example Edit thean image update

<?php
   session_start();
   include("connection.php");
   if(!$_SESSION['hello'])
   {
      echo "<script>window.location='registar.php'</script>";
   }
     $id=$_GET['id'];
   $sql="select * from reg where rid=$id";
   $sqlexcu=mysqli_query($dd,$sql);
   $fetch=mysqli_fetch_array($sqlexcu);
?>
<!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>Untitled Document</title>
</head>
<body>
    <form name="f1" method="post" enctype="multipart/form-data">
        <table border="1">
              <tr>
                  <th colspan="2">My Profile</th>
              </tr>
              <tr>
                  <th>Name</th>
                  <td><input type="text" name="txtname" value="<?php echo    $fetch['name']; ?>" /></td>
              </tr>
              <tr>
                      <th>User Name</th>
                    <td><input type="text" value="<?php echo $fetch['uname']; ?>"  disabled="disabled"/></td>
              </tr>
              <tr>
                  <th>Email</th>
                  <td><input type="text" name="txtemail" value="<?php echo $fetch['uemail']; ?>" /></td>
              </tr>
              <tr>
                      <th>Mobile Number</th>
                    <td><input type="text" name="txtmono" value="<?php echo $fetch['phonenum']; ?>"  /></td>
              </tr>
              <tr>
                      <th>Address</th>
                    <td><textarea name="txtadd"><?php echo $fetch['address']; ?></textarea></td>
              </tr>
              <tr>
                      <th>Postal Code</th>
                    <td><input type="text" name="txtcode" value="<?php echo $fetch['postcode']; ?>"  /></td>
              </tr>
              <tr>
                      <th>About me</th>
                    <td><textarea name="txtabtme"> <?php echo $fetch['aboutme']; ?></textarea></td>
              </tr>
              <tr>
                      <th>Image</th>
                    <td> <input type="file" name="file"  /></td>
              </tr>
              <tr>
                      <th>Password</th>
                    <td> <input type="password" name="txtpass" value="<?php echo $fetch['pass']; ?>"  /></td>
              </tr>
              <tr>
                       <td colspan="2"> <center> <input type="submit" name="btnupdate" value="Update" /></center></td>
              </tr>
            
        </table>
    </form>
    <?php
        if(isset($_POST['btnupdate']))
        {
            $txtname=$_POST['txtname'];
            $txtemail=$_POST['txtemail'];
            $txtmono=$_POST['txtmono'];
            $txtadd=$_POST['txtadd'];
            $txtcode=$_POST['txtcode'];
            $txtabtme=$_POST['txtabtme'];
            $f1=$_FILES['file']['name'];
            $tmp=$_FILES['file']['tmp_name'];
           
            $txtpass=$_POST['txtpass'];
           
            if($f1)
            {
            $rand=rand(1,5000000);
            $imag=$rand.$f1;
            $path= "imag/".$imag;
                 move_uploaded_file($tmp,$path);
            }
               if($f1=="")
               {
             $update="update reg set name='$txtname',uemail='$txtemail',phonenum='$txtmono',address='$txtadd',postcode='$txtcode',aboutme='$txtabtme',pass='$txtpass' where rid=$id ";
                }
                else {
            $update="update reg set name='$txtname',uemail='$txtemail',phonenum='$txtmono',address='$txtadd',postcode='$txtcode',aboutme='$txtabtme',pimage='$imag',pass='$txtpass' where rid=$id ";
                }
            $updateexcu=mysqli_query($dd,$update);   
            if(!$updateexcu)
            {
              echo  mysql_error();   
            }
            else {
             echo "<script>window.location='profile.php'</script>";
                }
    }
    ?>
</body>
</html>

Thursday, 9 July 2015

server side validation in php all field in PHP

<?php
session_start();
include("connection.php");
 $error="";
?>
<?php if (isset($error)) { echo "<p class='message'>" .$error. "</p>" ;} ?>
 <?php
 ini_set("display_errors",0);
    if(isset($_POST['btnadd']))
    {
       
         // $txtname=$_POST['txtname'];
         $txtname=$_POST['txtname'];
          $txtuname=$_POST['txtuname'];
         $txtemail=$_POST['txtemail'];
         $txtphonenum=$_POST['txtphonenum'];
         $txtadd=$_POST['txtadd'];
       
          $txtcode=$_POST['txtcode'];
       
         $txtabout=$_POST['txtabout'];
         $txtpass=$_POST['txtpass'];
         $txtconpass=$_POST['txtconpass'];
           $file=$_FILES['file']['name'];
   
             $rand=rand(1,5000000);
              $img=$rand.$file;
           
               move_uploaded_file($_FILES['file']['tmp_name'],"imag/".$img);
               $pass=$_POST['txtconpass'];
           
              // $date = date('Y-m-d H:i:s');
             
               $status='Active';
                 if($txtname == "")
               {
                    // null chak name field
                   
                    echo $error="Please Enter name";
                    $code="1";
               }
               elseif(!preg_match("/^[a-zA-Z]+$/",$txtname))
                 {       
                       // chack name field only char
                           echo  $first_nameErr = "Only letters  allowed";
                        $code="1";
                  }
               elseif($txtemail=="")
               {
                   echo $error="Please Enter Email";
                   $code="2";
               }
               elseif(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i",$txtemail))
               {
                  echo  $error ="Please Enter valid Email";
                  $code="2";
               }
               elseif($txtphonenum=="")
               {
                    echo  $error= "Please Enter Mobile Number";
                    $code="3";
               }
               elseif(!preg_match("/^\d{10}$/",$txtphonenum))
               {
                   echo $error = "Please Enter 10 Digit number";
                   $code= "3";
                  
               }
               elseif(trim($txtadd)=="")
               {
                    echo $error="Please Enter Your Address";
                    $code="4";
               }
               elseif(strlen($txtadd) < 60)
               {
                    echo $error = "Please at least 60 word write";
                    $code = "4";
               }
               elseif($txtcode=="")
               {
                      echo $error ="Please Enter Pincode ";
                      $code= "5";
               }
               elseif(!preg_match("/^\d{6}$/",$txtcode))
               {
                       echo $error = "Enter must be 6 Digit";
                    $code = "5";
               }
               elseif(trim($txtabout)=="")
               {
                       echo $error = "Please enter a About me";
                    $code="6";
               }
               elseif(strlen($txtabout) < 120)
               {
                   echo $error = "Please at least 120 word write";
                   $code = "6";
               }
               elseif($txtpass=="")
               {
                 echo $error= "Please Enter password";
                 $code = "7";
               }
               elseif(strlen($txtpass) < 8)
               {
                   echo $error = "Please at lease 8  char length";
                   $code = "7";
               }
               elseif($txtconpass=="")
               {
                    echo $error = "Please Enter confirm password";
                    $code= "8";
               }
               elseif($txtconpass !=$txtpass)
               {
                   echo $error = "Your Password is not match";
                   $code = "8";
               }
               elseif(!preg_match("/[0-9a-zA-Z]/",$txtconpass))
               {
                   echo  $error= "Please Enter Char";
                   $code = "8";
               }
               elseif(!preg_match("/[@$,<>#:?_*&;]/",$txtconpass))
               {
                   echo $error = "Pleace Enter at least one special char ";
                   $code = "8";
               }
               else
                   {
                   $sql="insert into reg(name,uname,uemail,phonenum,address,postcode,aboutme,pimage,pass,rdate,status) values('$txtname','$txtuname','$txtemail','$txtphonenum','$txtadd','$txtcode','$txtabout','$img','$txtconpass',now(),'$status')"; 
         $sqlexcu=mysqli_query($dd,$sql);
                  echo "submit";
                   }

         if(!$sqlexcu)
         {
           echo mysql_error();   
         }
         else {
             echo "<script>alert('Your Registration successfully');</script>";
            }
  }
   ?>
<style type="text/css" >

.error{border:1px solid red; }

.message{color: red; font-weight:italite;}

</style>

 <form name="f2" id="f2" method="post" enctype="multipart/form-data" style=" margin-top: -100px;"  onsubmit="return chkform(this);">
     <table border="1">
          <tr>
             <th colspan="2">Registration Form</th>
          </tr>
         
          <tr>
              <th>Name</th>
              <td><input type="text" name="txtname" placeholder="Enter Name" value="<?php if(isset($txtname)) {  echo $txtname; }   ?>" <?php if(isset($code) && $code == 1){echo "class=error";} ?> /></td>
          
          </tr>
          <tr>
              <th>User Name</th>
              <td><input type="text" name="txtuname"  placeholder="Enter User Name" onblur="userchaked(this.value)"/></td>
              <span id="msg"></span>
              
          </tr>
          <tr>
             <th>Email</th>
             <td><input type="text" name="txtemail" placeholder="Enter email Addres" value="<?php if(isset($txtemail)) { echo $txtemail; } ?>"   <?php if(isset($code) && $code == 2){echo "class=error";} ?> /> </td>
         
          </tr>
          <tr>
             <th>Phone number</th>
             <td><input type="text" name="txtphonenum" placeholder="Enter Phone number" value="<?php  if(isset($txtphonenum)) { echo $txtphonenum; } ?>"  <?php if(isset($code) && $code == 3) { echo "class=error";  } ?> /> </td>
         
          </tr>
         
          <tr>
             <th>Address</th>
             <td><textarea name="txtadd" <?php if(isset($code) && $code == 4) {  echo "class=error"; } ?> > <?php if(isset($txtadd)) {  echo $txtadd; } ?> </textarea></td>
          </tr>
          <tr>
              <th>Post code</th>
              <td><input type="text" name="txtcode" placeholder="Enter Postal Code" value="<?php if(isset($txtcode)) { echo $txtcode;  } ?>" <?php  if(isset($code) && $code == 5) {  echo "class=error"; } ?> /></td>
          </tr>
          <tr>
             <th>About Me</th>
             <td><textarea name="txtabout" <?php if(isset($code) && $code == 6) {  echo "class=error";  } ?>  > <?php if(isset($txtabout)) { echo $txtabout;   } ?>  </textarea></td>
          </tr>
          <tr>
            <th>Profile Image</th>
            <td><input type="file" name="file" id="imgfile" onchange="readURL(this)";/></td>
            <img id="preview" src="#" alt="." />
          </tr>
          <tr>
             <th>Password</th>
             <td><input type="password" name="txtpass" placeholder="Enter Password" value="<?php if(isset($txtpass))  {  echo $txtpass; } ?>" <?php  if(isset($code) && $code == 7)  { echo "class=error"; } ?> /></td>
          </tr>
          <tr>
             <th>Confirm Password</th>
             <td><input type="password" name="txtconpass"  placeholder="Enter Confirm password" value="<?php if(isset($txtconpass)) {  echo $txtconpass; } ?>" <?php if(isset($code) && $code == 8) { echo "class=error";  } ?> /></td>
              <input type="hidden" name="a1" value="" id="a1" />
          </tr>
          <tr>
             <td colspan="2"><center><input type="submit" name="btnadd"   /></center></td>
          </tr>
        
     </table>
 </form>

Wednesday, 8 July 2015

Image upload before image preview with javascript

<script type="text/javascript">
 function chkform(form)
{
  // image preview
   function readURL(input)
   {
    if (input.files && input.files[0])
{
        var reader = new FileReader();
        reader.onload = function (e) {
            document.getElementById('preview').src=e.target.result;
        }
        reader.readAsDataURL(input.files[0]);
    }
  }
    </script>
   
     <form name="f2" method="post" enctype="multipart/form-data" style=" margin-top: -100px;"  onsubmit="return chkform(this);">
    <<input type="file" name="file" id="imgfile" onchange="readURL(this)";/>
            <img id="preview" src="#" alt="your image" />
      </form>
   
 
 
  

username chacked with Ajax

<script type="text/javascript">
 function chkform(form)
{
   var ar = document.getElementById("a1").value;
if(ar=="true")
{

}
else {
return false;
}
   function userchaked(str)
   {
    if(window.XMLHttpRequest)
{
xmlhttp= new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function()
{
  if(xmlhttp.readyState==4 && xmlhttp.status==200)
  {
    document.getElementById("msg").innerHTML = xmlhttp.responseText;
if(xmlhttp.responseText=='USER NAME NOT VALID')
{
  document.getElementById("a1").value= "false";

}
else {
document.getElementById("a1").value= "true";
}
  }
}
xmlhttp.open("GET","ajax.php?id="+str,true);

xmlhttp.send();
  }
    </script>
   
     <form name="f2" method="post" enctype="multipart/form-data" style=" margin-top: -100px;"  onsubmit="return chkform(this);">
     <input type="text" name="txtuname"  placeholder="Enter User Name" onblur="userchaked(this.value)"/>
   
     //this hidden field
      <input type="hidden" name="a1" value="" id="a1" />
   
   
    </form>
   
   
 
  

Tuesday, 7 July 2015

Postal or pincode and Address length validation with javascript

<script type="text/javascript">

   function chkform(form)

   {
   //address validation must be 60 char

if(form.txtadd.value.length < 60 )
        {

 alert("At least  60 word Write ");
 form.txtadd.focus();
 return false;
}

// postal code
re = /^\d{6}$/;

if(!re.test(form.txtcode.value))

      {
 alert("Enter 6 Digit pincode ");
 form.txtcode.focus();
 return  false;
}

 
   }
    </script>
   
     <form name="f2" method="post" enctype="multipart/form-data" style=" margin-top: -100px;"  onsubmit="return chkform(this);">
   
      <textarea name="txtadd"></textarea>
          <input type="text" name="txtcode" placeholder="Enter Postal Code" />
   
    </form>

How to Mobile validation with javascript

<script type="text/javascript">

   function chkform(form)

   {
 
   // Phone number validation
re=  /^\d{10}$/;
if(!re.test(form.txtphonenum.value))
{
alert("Enter Only  10 Digit Number");
form.txtphonenum.focus();
return false;
}
   }
 
   </script>
 
   <form name="f1" method="post" style="margin-left: 500px;">
   <input type="text" name="txtphonenum" placeholder="Enter Phone number"/>
   </form> 

simple email validation with javascript

<script type="text/javascript">

   function chkform(form)

   {

  re= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (!re.test(form.txtemail.value)) {
    alert('Please provide a valid email address');
    form.txtemail.focus();
    return false;
 }


}
</script>

 <form name="f2" method="post" enctype="multipart/form-data" style=" margin-top: -100px;"  onsubmit="return chkform(this);">

<input type="text" name="txtemail" placeholder="Enter email Addres"/>
</form>

simple name field validation only character allowed used javascript

<script type="text/javascript">

   function chkform(form)

   {
   



 
re =/^[a-zA-Z]+$/
if(!re.test(form.txtname.value))
{
alert("Only Character Allowed ");
form.txtname.focus();
return false;
}

</script>

<form name="f1" method="post" style="margin-left: 500px;">
<input type="text" name="txtname" placeholder="Enter Name" />
</form>

confirm password validation javascript code

<script type="text/javascript">

   function chkform(form)

   {
      if(form.txtpass.value != "" && form.txtpass.value == form.txtconpass.value)
 {
if(form.txtpass.value.length < 8)
{
   alert("at least 8 char allow");
form.txtpass.focus();
return false;
}
//


 re = /[0-9]/;
 if(!re.test(form.txtpass.value))
 {
   alert("please at least one number");
form.txtpass.focus();
return false;

 }

  re = /[a-z]/;
  if(!re.test(form.txtpass.value))
  {
    alert("please at least one lower case");
form.txtpass.focus();
return false;
  }
 


  re = /[A-Z]/;
  if(!re.test(form.txtpass.value))
  {
alert("at least one Upper case");

form.txtpass.focus();
return false;
}
re= /[@$,<>#:?_*&;]/;
if(!re.test(form.txtpass.value))
{
  alert("at least one special char ");
  form.txtpass.focus();
  return false;

   }


 }
 else {
 alert("this feild is required");
 form.txtpass.focus();
 return false;

 }
 return true;
   }
</script>

 <form name="f2" method="post" enctype="multipart/form-data" style=" margin-top: -100px;"  onsubmit="return chkform(this);">
<input type="password" name="txtpass" placeholder="Enter Password"/>
<input type="password" name="txtconpass"  placeholder="Enter Confirm password"/>
</form>