title: How to retain $_REQUEST["id"] value upon page reloading
body: <p>I have a contact form in PHP. I have a code for editing my contact details in the database. The code checks for errors in the values posted, and displays a error message. But the page reloads upon form submission and the <code>$_REQUEST["id"]</code> is lost. 
  How can I retain the <code>$_REQUEST["id"]</code> upon page reloading?</p>
  
  <p>My <code>edit.php</code> is as follows:</p>
  
  <pre><code>&lt;?php 
      session_start();
   ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
  
      &lt;style&gt;
          //styling
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;?php
  
      //$_REQUEST["id"] = $_SESSION["name"];
  
      $_SESSION["name"] = $_REQUEST["id"];
  
      echo $_SESSION["name"]." ".$_REQUEST["id"];
  
      $first_name = $_SESSION["name"];
  
      $_SESSION["name"] = "";
  
      $server_name = "localhost";
      $user_name = "username";
      $password = "password";
      $db_name = "myDB";
  
      $connection = new mysqli ($server_name, $user_name, $password, $db_name);
  
      $stmt = $connection-&gt;prepare("SELECT * FROM Contact WHERE first_name = ?");
      $stmt-&gt;bind_param("s", $first_name);
      $stmt-&gt;execute();
      $row = $stmt-&gt;get_result();
      $result = $row-&gt;fetch_assoc();
  
      ?&gt;
  
      &lt;?php 
          $first_name = $last_name = $email = $phone_number = $gender = $date_of_birth = "";
          $first_name_err = $last_name_err = $gender_err = $email_err = $phone_number_err = $address_err = $captcha_err = "";
          if(isset($_POST['submit']))
          {
              if(empty($_POST["first_name"]))
                  $first_name_err = "First Name is required";
              else{
                  $first_name = test_input($_POST["first_name"]);
                  if (!preg_match("/^[a-zA-Z ]*$/",$first_name))
                      $first_name_err = "Only letters and white space allowed";
                  if(strlen($first_name) &lt; 3 || strlen($first_name) &gt; 15)
                      $first_name_err = "Length mismatch (3 &lt;= length &lt;= 15)";
              }
  
              if(empty($_POST["last_name"]))
                  $last_name = "";
              else{
                  $last_name = test_input($_POST["last_name"]);
                  if (!preg_match("/^[a-zA-Z ]*$/",$last_name))
                      $last_name_err = "Only letters and white space allowed";
                  if(strlen($last_name) &lt; 3 || strlen($last_name) &gt; 15)
                      $last_name_err = "Length mismatch (3 &lt;= length &lt;= 15)";
              }
  
              if(empty($_POST["email"]))
                  $email_err = "Email is required";
              else{
                  $email = test_input($_POST["email"]);
                  if (!filter_var($email, FILTER_VALIDATE_EMAIL))
                          $email_err = "Invalid email format";
                  if(strlen($email) &lt; 6 || strlen($email) &gt; 64)
                      $email_err = "Length mismatch (6 &lt;= length &lt;= 64)";
              }
  
              if(empty($_POST["phone_number"]))
                  $phone_number_err = "Phone Number is required";
              else{
                  $phone_number = test_input($_POST["phone_number"]);
                  if (!preg_match("/^[0-9]*$/",$phone_number))
                          $phone_number_err = "Only numbers allowed";
                  if(strlen($phone_number) != 10)
                          $phone_number_err = "Invalid number";
              }
  
              if(empty($_POST["gender"]))
                  $gender_err = "Gender required";
              else
                  $gender = test_input($_POST["gender"]);
  
              //if(!empty($date_of_birth))
                  $date_of_birth = test_input($_POST["date_of_birth"]);
  
  
  
  
              if(empty($_POST["captcha"]))
                  $captcha_err = " * Captcha required";
              else{
                  if($_POST["captcha"] != $_SESSION["captcha"])
                      $captcha_err = "Incorrect captcha";
              }   
          }
  
          function test_input($data){
              //functon to test the input for scripts
              //Input: $data
              //Output: $data
              $data = trim($data);
              $data = stripslashes($data);
              $data = htmlspecialchars($data);
              return $data;
          }
      ?&gt;
  
      &lt;form action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?&gt;" method="post"&gt;
      &lt;span class="error"&gt;* Required&lt;/span&gt; &lt;br&gt;
      &lt;label id="first_name_label"&gt;First Name: &lt;/label&gt; &lt;input type="text" name="first_name" value="&lt;?php echo $result["first_name"]; ?&gt;" required="required" placeholder="Enter first name"&gt; &lt;span class="error"&gt; * &lt;?php echo "$first_name_err";  ?&gt; &lt;/span&gt; &lt;br&gt; 
      &lt;label id="last_name_label"&gt;Last Name: &lt;/label&gt; &lt;input type="text" name="last_name" value="&lt;?php echo $result["last_name"]; ?&gt;" placeholder="Enter last name"&gt; &lt;span class="error"&gt; &lt;?php echo "$last_name_err"; ?&gt; &lt;/span&gt; &lt;br&gt;
      &lt;label id="email_label"&gt;E-Mail: &lt;/label&gt; &lt;input type="email" name="email" value="&lt;?php echo $result["email"]; ?&gt;" required="required" placeholder="Enter email"&gt; &lt;span class="error"&gt; * &lt;?php echo "$email_err"; ?&gt; &lt;/span&gt; &lt;br&gt;
      &lt;label id="phone_number_label"&gt;Phone Number: &lt;/label&gt; &lt;input type="text" name="phone_number" value="&lt;?php echo $result["phone_number"]; ?&gt;" required="required" placeholder="Enter phone number"&gt; &lt;span class="error"&gt; * &lt;?php echo "$phone_number_err"; ?&gt; &lt;/span&gt; &lt;br&gt;
      &lt;label id="gender_label"&gt;Gender:&lt;/label&gt;
          &lt;input type="radio" name="gender" &lt;?php if($result['gender']=="Male") echo "checked";?&gt; value="Male"&gt;Male
          &lt;input type="radio" name="gender" &lt;?php if ($result['gender']=="Female") echo "checked";?&gt; value="Female"&gt;Female
          &lt;input type="radio" name="gender" &lt;?php if ($result['gender']=="Other") echo "checked";?&gt; value="Other"&gt;Other &lt;span class="error"&gt; * &lt;?php echo "$gender_err"; ?&gt; &lt;/span&gt; &lt;br&gt;
      &lt;label id = "date_of_birth_label"&gt; Date of Birth: &lt;/label&gt; &lt;input type="text" name="date_of_birth"value="&lt;?php echo $result["date_of_birth"]; ?&gt;" placeholder="dd-mm-yyyy"&gt; &lt;br&gt;
      &lt;label id="captcha_label"&gt;Enter Captcha: &lt;/label&gt; &lt;img src="captcha.php" width="120" height="30" border="1" &gt; &lt;br&gt; &lt;label id="captcha_label1"&gt; &lt;/label&gt; &lt;input type="text" name="captcha" required="required" placeholder="Enter Captcha"&gt; &lt;span class= "error"&gt; * &lt;?php echo "$captcha_err"; ?&gt; &lt;/span&gt; &lt;br&gt;  
      &lt;br&gt;
      &lt;input type="submit" name="submit" value="Update"&gt;  
      &lt;/form&gt;
      &lt;?php
          if($_SERVER["REQUEST_METHOD"] == "POST")
          {
              if(isset($_POST["first_name"]) &amp;&amp; isset($_POST["last_name"]) &amp;&amp; isset($_POST["gender"]) &amp;&amp; isset($_POST["email"]) &amp;&amp; isset($_POST["phone_number"]) &amp;&amp; isset($_POST["captcha"]))
              {
                  if ($first_name_err == "" &amp;&amp; $last_name_err == "" &amp;&amp; $gender_err == "" &amp;&amp; $email_err == "" &amp;&amp; $phone_number_err == ""  )//&amp;&amp; $captcha_err == "")
                  {
                      $insert_date = $date_of_birth;
  
  
                      $sql_db = "REPLACE INTO Contact (first_name, last_name, email, phone_number, gender, date_of_birth) VALUES ('$first_name', '$last_name', '$email', '$phone_number', '$gender', '$insert_date') ";
  
                      $connection-&gt;query($sql_db);
  
                      $connection-&gt;close();
  
                      $_SESSION["edit_message"] = "Contact Details Edited Successfully";
  
                      unset($_SESSION["name"]);
  
                      header("Location: http://localhost/test/display.php?show_details=Show+Details");
  
                  }
              }
          }
      ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've tried storing it in a <code>SESSION</code> variable, but the session variable does not change on tring to edit a different data.
  I'm new to php. Help please...</p>