title: html form,db submission,empty data on refresh or back
body: <p>I have a from submitting data to db,and after entering in to db thank you message comes,everything is in same page.the problem is wheni refresh or go back the same data or empty data is entered in to db. Please help`</p>
  
  <pre><code>&lt;?php
  $myServer = "localhost";
  $myUser = "root";
  $myPass = "";
  $myDB = "sample"; 
  
  $name=$_POST['fname'];
  $mobile=$_POST['mobile'];
  $email=$_POST['email'];
  //connection to the database
  $dbhandle = mysql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer"); 
    //select a database to work with
  $selected = mysql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB"); 
  //echo "$myDB";
  //Insert data into db 
   mysql_query("INSERT INTO reg(name,mobile,email) values ('$name','$mobile','$email')");
   /* echo "$name";
  echo "$mobile";
  echo "$email";  */
  //header("location:thank.html");
  
  
  ?&gt;
  
  
  &lt;!doctype html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Basic form with validation&lt;/title&gt;
          &lt;link rel="stylesheet" href="style/style.css" type="text/css" media="all"/&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div style="width:300px; background:#19a3d1;margin:0 auto;height:200px;"&gt;
      &lt;?php
          if(empty($_POST))
          {
          ?&gt;
  
          &lt;form name="myform" id="frm1" action="index.php" method="post" style="margin:0 auto;"onsubmit="return(validate());"&gt;
              &lt;h1 style="text-align:center"&gt;Form&lt;/h1&gt;
              &lt;div  style="display: table; margin:0 auto;"&gt;
                  &lt;div style="display: table-row;"&gt;
                      &lt;div style="display: table-cell;padding:5px;"&gt;
                          &lt;label&gt;Name&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div style="display: table-cell;"&gt;
                          &lt;input type="text" name="fname" id="fname" placeholder="Name" /&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div style="display: table-row;"&gt;
                      &lt;div style="display: table-cell;padding:5px;"&gt;
                          &lt;label&gt;Mobile&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="text" name="mobile" id="mobile" placeholder="Mobile" /&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div style="display: table-row;"&gt;
                      &lt;div style="display: table-cell;padding:5px;"&gt;
                          &lt;label&gt;Email&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="text" name="email" id="email" placeholder="Email" /&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div style="display: table-row;"&gt;
                      &lt;div style="display: table-cell;padding:5px;" &gt;&lt;/div&gt;
                      &lt;div style="display: table-cell;padding:5px;"&gt;&lt;input type="submit" value="Submit"&gt;&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  
          &lt;?php
          }
          else{
          ?&gt;
  
          &lt;div id="thank" &gt;
              &lt;span style="color:#ff0000;padding:30px;text-align:center;display:block;"&gt;Thank you!!&lt;/span&gt;
          &lt;/div&gt;
          &lt;?php
          }
          ?&gt;
          &lt;/div&gt;
  
  
          &lt;script src="js/main.js"&gt;&lt;/script&gt;
          &lt;script src="http://code.jquery.com/jquery-1.11.0.min.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;`
  </code></pre>