title: how to include php validation functions from another php file
body: <p>Hello im new to web designing,i create one form to give statecode and statename. validation for this form in php and the validation done in another file.i dont know how to include the validation.please help me to validate and after to store in database.here i will attach all the files please help me friends.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function stateAjaxsubmit()
  {  
      var statename = document.forms["addstate"]["statename"].value;
      var statecode = document.forms["addstate"]["statecode"].value;
    
      var valueJson = {
          "State_Code": statecode,
          "State_Name": statename
      };
      
      console.log("Input");
      console.log(valueJson);
    
       $.ajax(
    { 
          dataType: "json",
          cache: false,      
          contentType: "application/json; charset=utf-8",
    url : "tocheck.php",
    type: "POST",
    data :JSON.stringify(valueJson),
    success:function(data, textStatus, jqXHR)
    {
    console.log("Output");
                  console.log(data);
    },
    error: function(jqXHR, textStatus, errorThrown)
    {
    }    
      });
      </code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>&lt;?php
  include('php/dbconnection.php');
  include('validations.php');
  include('Samplestates.php');
  $data = json_decode(file_get_contents('php://input'));
  header('Content-Type: application/json');
   $head = json_encode($data);
   echo $head;
  $id = $data-&gt;State_Code;
  $name = $data-&gt;State_Name;
  
  function doSubmit(){       
      if (checkFormvalues()) 
          {
           $value = ('#addstate').submit();
      }
  }
  $sql="INSERT INTO m_state1(State_Code, State_Name, Created_By, Created_Date) 
  VALUES ('$id', '$name', '1000',now())";
  $res=mysqli_query($con,$sql) or die('Error: '. mysqli_error($con));
  
  ?&gt;
  
  
  Samplestates.php
  
  &lt;?php
  function checkFormvalues($statecode, $statename)
  {
    $msg = "";
    $isstatecode = false;
    $isstatename = false;
    $ismsg = false;    
                  $data = array();
                  
    //function to check null
    if(checkNullvalue($statecode))
    {
     //length must be 3
     if(checkCodeLen($statecode))
     {
      //check alphanumeric
      if(checkAlphabets($statecode))
      {
       $isstatecode = true;
      }
      else
      {
       $isstatecode = false;
       $msg .= "Code must be Alphabet";
                                          array_push($data, array("Code" =&gt; $msg));
      }
     }
     else
     {
      $isstatecode = false;
      $msg .= "Length must be three charcter";
                                  array_push($data, array("Code" =&gt; $msg));
     }
    }
    else
    {
     $isstatecode = false;
     $msg .= "Code must be filled out";
                          array_push($data, array("Code" =&gt; $msg));
    }
    
                  $msg = "";
                  
    //function to check null
    if(checkNullvalue($statename))
    {
      //check alphabet
      if(checkAlphabets($statename))
      {
       $isstatename = true;
      }
      else
      {
       $isstatename = false;
       $msg .= "Name must be Alphabet";
                                          array_push($data, array("Name" =&gt; $msg));
      }
    }
    else
    {
     $isstatename = false;
     $msg .= "Name must be filled out";
                          array_push($data, array("Name" =&gt; $msg));
    }
    
    if(empty($data))
    {
     $ismsg = true;
                          array_push($data, array("Result" =&gt; $ismsg));
    }
    else
    {
     $ismsg = false;                        
                          array_push($data, array("Result" =&gt; $ismsg));
    }
    
                  $outData = array("Response" =&gt; $data);
    
                  echo json_encode($outData);
                  
    return json_encode($outData);
  }
  ?&gt;
  
  validations.php
  
  &lt;?php
  //function to check null values
  function checkNullvalue($e)
  {
   if (empty($e)) 
   {
          return false; 
   }
   else
   {
    return true;
   }
  }
  
  function checkCodeLen($value)
  {
   if(strlen($value) &gt; 3)
   {
    return false;
   }
   else
   {
    return true;
     }   
  }
  
  function checkAlphabets($alphabet)
  { 
   if(ctype_alpha($alphabet)) 
   {
       return true;
   }
   else
   {
       return false;
      }
  }
  
  function toupper($value)
  {
   $upper = strtoupper($value);
   return $upper;
  }
  ?&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;link href="css/Addcaste.css" rel="stylesheet" /&gt;
  &lt;script src="js/jquery-1.11.0.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/Validation.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/State.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;p&gt;&lt;center&gt;State Entry&lt;/center&gt;&lt;/p&gt;
      &lt;form method="post" class="r" name="addstate" id="addstates" onSubmit="return doSubmit()" action="#"&gt;
      &lt;div&gt;
      &lt;table align="center"&gt;
    
       &lt;td&gt;State Code&lt;/td&gt;
       &lt;td&gt;&lt;input type="text" id="statecode" name="statecode" autocomplete="off" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
       &lt;td&gt;State Name&lt;/td&gt;
       &lt;td&gt;&lt;input type="text" name="statename" id="statename" autocomplete="off"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
       &lt;td&gt;&lt;input type="submit" name="submit" value="Add" id="submit" /&gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="reset" name="reset" value="Cancel" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>