title: Database gets populated on page refresh
body: <p>I have a script which validates and submits the data to the MySQL database but whenever the Index page is refreshed or revisited in a new tab in both the case the database gets populated. The populated data is BLANK. I want to stop this automated resubmission of data but not sure how to do it. </p>
  
  <p>This is my script that validates and submits the data to the database.</p>
  
  <pre><code>&lt;?php include('includes/config.php');
      // define variables and set to empty values
  $nameErr = $contactErr = $cityErr = $serviceErr = "";
  $name = $contact = $city = $service = "";
  
  function test_input($data) 
    {
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
    }
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
     if (empty($_POST["name"])) {
       $nameErr = "* Name is required";
     } else {
       $name = test_input($_POST["name"]);
       // check if name only contains letters and whitespace
       if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
         $nameErr = "* Only letters and white space allowed";
       }
     }
  
     if (empty($_POST["contact"])) {
       $contactErr = "* Contact is required";
     } else {
       $contact = test_input($_POST["contact"]);
       // check if contact number is well-formed
       if (!preg_match("/^[0-9+]*$/",$contact)) {
         $contactErr = "* Phone number should contain only numbers";
       }
     }
  
     if (empty($_POST["city"])) {
       $cityErr = "* City is required";
     } else {
       $city = test_input($_POST["city"]);
       // check if city is valid
       if (!preg_match("/^[a-zA-Z ]*$/",$city)) {
         $cityErr = "* Only letters and white space allowed";
       }
     }
  
     if (empty($_POST["service"])) {
       $serviceErr = "* Service is required";
     } else {
       $service = test_input($_POST["service"]);
     }
   } 
  
      $myDb-&gt;connect();
      $query = "INSERT INTO user_profile (name, city, contact, service)VALUES('$name', '$city', '$contact', '$service')";
      mysql_query($query) or die(mysql_error());
      $myDb-&gt;close();
      $display_error = "Data submitted successfully."; 
  
  
  ?&gt;
  </code></pre>
  
  <p>This is my form.</p>
  
  <pre><code> &lt;form action="index.php"  method="post"&gt;
  
      &lt;table style="line-height: 50px;"&gt;
          &lt;tr&gt;
            &lt;th&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/th&gt;
            &lt;td&gt;&lt;input type="text" name="name" placeholder="Your Name" style="height:30px; border:1px; width:300px; border-radius:5px; text-indent:15px"&gt;&lt;span class="error"&gt; &lt;?php echo $nameErr;?&gt;&lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;br&gt;
          &lt;tr&gt;
            &lt;th&gt;Phone&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/th&gt;
            &lt;td&gt;&lt;input type="text" name="contact" placeholder="Your Contact Number" style="height:30px; border:1px; width:300px; border-radius:5px; text-indent:15px"&gt;&lt;span class="error"&gt; &lt;?php echo $contactErr;?&gt;&lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;City&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/th&gt;
            &lt;td&gt;&lt;input type="text" name="city" placeholder="Your City Name" style="height:30px; border:1px; width:300px; border-radius:5px; text-indent:15px"&gt;&lt;span class="error"&gt; &lt;?php echo $cityErr;?&gt;&lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;Service&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/th&gt;
            &lt;td&gt;&lt;select name="service" autocomplete="off" style="height:30px; border:1px; width:300px; border-radius:5px;"&gt;
                &lt;option value=""&gt;Select your service&lt;/option&gt;
                &lt;option value=service1&gt;Service 1&lt;/option&gt;
                &lt;option value=service2&gt;Service 2&lt;/option&gt;
                &lt;option value=service3&gt;Service 3&lt;/option&gt;
                &lt;option value=service4&gt;Service 4&lt;/option&gt;
                &lt;/select&gt;&lt;span class="error"&gt; &lt;?php echo $serviceErr;?&gt;&lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;input type="submit" name="submit" value="Submit" style="height: 40px; width: 140px; border-radius: 5px; margin-left: 140px;margin-top: 20px;"&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>I don't know what mistake I am making. Everytime I open my index.php page that contains the form, automatically a new BLANK DATABASE is added. How can I prevent this? Please help me.</p>