title: html form submit calls a php but does not redirect
body: <p>Ok friends I am very confused with this basic thing. I have read lot of posts where it says, I need to add SELF POST or something but I am not understanding.</p>
  
  <p>I have two files, index.html and submit.php. index.html has a form with a submit button by clicking which, the submit.php file is called and shows a message "1 record added". I want to redirect back from the submit.php file to index.html file. I dont know what I am doing wrong. Is it because one is html file and another php? Please help. Here is my code</p>
  
  <p>index.html file</p>
  
  <pre><code>&lt;form method="post" action="submit.php"&gt;
  </code></pre>
  
  <p>submit.php file</p>
  
  <pre><code>    &lt;?php
      $con = mysql_connect("localhost","myuser","mypassword");
      if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }
      mysql_select_db("mydb", $con);
      $sql="INSERT INTO members (sName, sCity, sMobile, sEmail, sSub, sSlogan)
      VALUES ('$_POST[name]', '$_POST[city]', '$_POST[mobile]', '$_POST[email]', '$_POST[sub]', '$_POST[slogan]')";
      if (!mysql_query($sql,$con))
        {
        die('Error: ' . mysql_error());
        }
      echo "1 record added";
      mysql_close($con)
      ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Please find code of index.html and submit.php file. With your help, both are working perfect. I am still struggling where excatly to put the validation code. i am using html5 input types in html file and I dont know where exactly the validation to happen in submit.php file. Yes, I do have multiple forms and I made validations.php file as suggested by you. What I am not understanding is if you have function validate_name($input) for name field in validations.php file then why are you validating name again in submit.php? ( if (!empty($_POST['name']) ). I am also not understanding where will the error messages been shown? If I try to add these functions, it gives me blank page on clicking submit and the data does not go to database.</p>
  
  <p>Can you suggest a location in the submit.php file where I should add these validations by editing my submit.php file? 
  Regexp for email (<code>'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'</code>)
  Regexp for phone (<code>^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$</code>)</p>
  
  <p><strong>This is my index.html file</strong></p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;title&gt;My Title&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;form method="post" action="submit.php"&gt;
          &lt;div class="box"&gt;
              &lt;div class="cl"&gt;&lt;input type="text" name="name" placeholder="Name" /&gt;&lt;/div&gt;
              &lt;div class="cl"&gt;&lt;input type="text" name="city" placeholder="City" /&gt;&lt;/div&gt;
              &lt;div class="cl"&gt;&lt;input type="text" name="mobile" placeholder="Mobile" /&gt;&lt;/div&gt;
              &lt;div class="cl"&gt;&lt;input type="email" name="email" placeholder="Email" /&gt;&lt;/div&gt;
              &lt;div class="cl"&gt;&lt;input type="text" name="sub" placeholder="Want 3 m Free Subscription (Yes/No)?"&gt;&lt;/textarea&gt;&lt;/div&gt;
              &lt;div class="cl"&gt;&lt;input type="text" name="slogan" placeholder="Suggest a slogan for 6 m subscription"&gt;&lt;/textarea&gt;&lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="srow"&gt;
              &lt;div class="cl1"&gt;
                  &lt;ul class="action"&gt;
                      &lt;li&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>This is the submit.php file help that I took from you</strong></p>
  
  <pre><code>&lt;?php
  include 'config.php'; // store your configuration in a seperate file so 
                        // you only need to update it once when your environment changes
  
  $errors = false;
  $output = '';
  $nl = '&lt;br&gt;'.PHP_EOL;
  $redirect_url = 'index.html';
  
  if (!$con = new mysqli(DBHOST,DBUSER,DBPASS,DBNAME)){
      $errors = true;
      $output .= "ERROR Can't connect to DB".$nl;
  };   
  
  
  if (!$errors){
     //should validate/clean $_POST before using in query
     $name = $con-&gt;escape_string($_POST['name']);
     $city = $con-&gt;escape_string($_POST['city']);
     $email = $con-&gt;escape_string($_POST['email']);
     $mobile = $con-&gt;escape_string($_POST['mobile']);
     $sub = $con-&gt;escape_string($_POST['sub']);
     $slogan = $con-&gt;escape_string($_POST['slogan']);
  
     $sql="INSERT INTO members 
              (sName, sCity, sMobile, sEmail, sSub, sSlogan)
           VALUES ('$name', '$city', '$mobile', '$email',
                  '$sub','$slogan')";
  
     if (!$con-&gt;query($sql)){ //forgot a parenthesis here earlier
        $output .= 'ERROR: DB said: ('.$con-&gt;errno.') '.$con-&gt;error.$nl;
        $output .= 'Query was:'.$sql.$nl;
        $errors = true;
     }else{
       $output .= "1 record added".$nl;
     }
  }
  
  if (!$errors){
     //if there are no errors redirect to index.html;
     header('refresh: 2; URL='.$redirect_url);
     $output .= '...Redirecting...'.$nl;
  }else{
     //show the errors and allow display a link to go back/try again
     $output .= '&lt;a href="'.$redirect_url.'"&gt;Try again&lt;/a&gt;'.$nl;
  }
  echo $output;
  ?&gt;
  </code></pre>
  
  <p>PS: One thing I observed is that html5 (input type="email") shows invalid email alert immediately after you go to next field, just under the field. How is it possible to do it for all fields? (something like a validation check on field lost focus)</p>
  
  <p>Thanks</p>