title: POST variable is not working in SESSION
body: <p>I want to pass the value of <code>login.php</code> POST variables <code>$user_key</code> &amp; <code>$user_id</code> to another file <code>statusdata.php</code> for which I have used session. In <code>statusdata.php</code> I want to use those session variable value in the SQL query of <code>statusdata.php</code> file.</p>
  
  <p>To achieve this in <code>login.php</code>first I pass the value of POST variable <code>$_POST["user_key"]</code> &amp; <code>$_POST["id"]</code> to variable <code>$user_key</code> &amp; <code>$user_id</code> respectively then I pass the value of variable <code>$user_key</code> &amp; <code>$user_id</code> to session variable <code>$_SESSION["key"]</code> &amp; <code>$_SESSION["id"]</code> respectively then in <code>statusdata.php</code> I call session variable and pass their value in variable <code>$user_key</code> &amp; <code>$user_id</code> of <code>statusdata.php</code></p>
  
  <p>now the Problem is the value POST variable <code>$_POST["user_key"]</code> &amp; <code>$_POST["id"]</code> 
  are not going to the session to <code>statusdata.php</code> but if I give direct values of <code>$user_key</code> &amp; <code>$user_id</code> in <code>login.php</code> then session is working fine but not with POST variable </p>
  
  <p>Again I want to clear that POST variable is getting values from the user through an android app which ask <code>id</code> and <code>key</code> to authenticate the user from <code>login.php</code> and then move to another screen and retrieve data related to entered <code>id</code> and <code>key</code> using <code>statusdata.php</code></p>
  
  <p>help me to get the value of post variable from <code>login.php</code> in session so that it can be used in <code>statusdata.php</code>  </p>
  
  <p><strong><code>login.php</code></strong></p>
  
  <pre><code>&lt;?php
  
  // Start the session
  session_start();
  
  require "conn.php";
  
  if (isset($_POST["id"])) {
    $user_id = mysqli_real_escape_string($conn,$_POST["id"]);
  }
  
  if (isset($_POST["user_key"])) {
    $user_key = mysqli_real_escape_string($conn,$_POST["user_key"]);
  }
  
  /* USING THESE DIRECT VALUE IN PLACE OF POST VARIABLE IS WORKING FINE IN SESSION FOR BOTH `login.php` and `statusdata.php` which indicate there is no problem with `statusdata.php` but using POST variable is working fine for `login.php` as authenticating user with `id` and `key` but value of POST variable is not going to session in `statusdata.php`.  
  
  $user_key = "8c9333343c6c4222418edb1d7c9f84d051610526085960a1732c7c3d763fff64ec7f5220998434c896dda243ae777d0fb213f36b9b19f7e4a244d5c993b8dfed";
  $user_id = "96";
  */
  
  $mysql_qry = "select * from applications where application_key = '".$user_key."' and application_id = ".$user_id." ;";
  
  $result = mysqli_query($conn, $mysql_qry);
  if (mysqli_num_rows($result) &gt; 0){
      $_SESSION["key"] = $user_key;
      $_SESSION["id"] = $user_id;
      echo "Login Success";
  } else {
      echo "Login Not Success";   
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong><code>statusdata.php</code></strong></p>
  
  <pre><code>&lt;?php
  // Start the session
  session_start();
  
  require "conn.php";
  
  $user_key = "-1";
  if (isset($_SESSION["key"])) {
    $user_key = $_SESSION["key"];
  }
  
  $user_id = "-1";
  if (isset($_SESSION["id"])) {
    $user_id = $_SESSION["id"];
  }
  
   //creating a query
   $stmt = $conn-&gt;prepare("SELECT applications.application_id, applications.applicant_name, applications.applicant_aadhaar, applications.applicant_phone, applications.subject, applications.date, applications.description, applications.chairperson_remark, applications.status, officer_accounts.name_of_officer, applications.officer_remark, applications.last_update_on 
  FROM applications INNER JOIN officer_accounts ON applications.account_id = officer_accounts.account_id 
  WHERE applications.application_id = ? AND applications.application_key = ? ;");
  
   $stmt-&gt;bind_param('ss',$user_id,$user_key);
  
   //executing the query 
   $stmt-&gt;execute();
  
   //binding results to the query 
   $stmt-&gt;bind_result($id, $name, $aadhaar, $phone, $subject, $date, $description, $chairperson, $status, $officername, $officerremark, $lastupdate);
  
   $applications = array(); 
  
   //traversing through all the result 
   while($stmt-&gt;fetch()){
   $temp = array();
   $temp['applications.application_id'] = $id; 
   $temp['applications.applicant_name'] = $name; 
   $temp['applications.applicant_aadhaar'] = $aadhaar; 
   $temp['applications.applicant_phone'] = $phone; 
   $temp['applications.subject'] = $subject;
   $temp['applications.date'] = $date;
   $temp['applications.description'] = $description;
   $temp['applications.chairperson_remark'] = $chairperson;
   $temp['applications.status'] = $status;
   $temp['officer_accounts.name_of_officer'] = $officername;
   $temp['applications.officer_remark'] = $officerremark;
   $temp['applications.last_update_on'] = $lastupdate;
   array_push($applications, $temp);
   }
  
   //displaying the result in json format 
   echo json_encode($applications);
  
   // remove all session variables
  session_unset(); 
  
  // destroy the session 
  session_destroy(); 
  
  ?&gt;
  </code></pre>
  
  <p><strong>NOTE -</strong> I am taking the output of <code>statusdata.php</code> SQL query in JSON format as in the end I am extracting it in android. </p>
  
  <p><strong>Please help me I have tried everything which other similar questions are suggesting but nothing helps</strong> </p>