title: creating a Session variable in onclick() event of PHP submit button
body: <p>I created a form and have gone through a <a href="https://stackoverflow.com/questions/8524310/set-a-variable-in-session-when-the-submit-button-is-clicked-in-struts">similar question</a> on Stackoverflow as well, relating to this area of sending a variable from one page to another. </p>
  
  <p>I need to pass this value $id=$row['id']; to the next page, but if I store it in the session variable (inside the while lopp) then it stored only the last item and not the current value.</p>
  
  <pre><code>&lt;form name="send" method="POST" action="got.php"&gt;
   &lt;hidden id="value" name="value"/&gt;
  //&lt;input type="text" id="value"&gt;
  //&lt;input type="hidden" name="myVariable" value="'.  htmlentities("myVariable").'"&gt;;
  &lt;input type=submit name=submit value="submit"  onclick="&lt;?php session_start(); $_SESSION(this.id) ?&gt;"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The full code is given below,</p>
  
  <pre><code>echo "&lt;form name=payment action='properties_details.php'&gt;";
  echo "Results &lt;br&gt;";
  while ($row= mysql_fetch_array($result)) {
  echo " &lt;table border=3 cell padding=1&gt; &lt;tr&gt; &lt;td&gt; ";
  
  $id=$row['id'];
  $pid=$row['pref'];
  //And the remaining values as well      
  
  //&lt;input type="hidden" name="myVariable" value="'.  htmlentities($pid).'"&gt;;
  //&lt;input type="hidden" name="myVariable" value="'.  $pid.'"&gt;;
  
  echo "&lt;p&gt;Property ID &amp;nbsp".$pid;
  echo "&lt;br&gt; &lt;p&gt; Name &amp;nbsp";
  echo $row["name"];
  echo "&lt;br&gt;  Properties &amp;nbsp";
  echo $row["catergory"];
  // And printing the remaining values
  
  echo "&lt;input type=submit name=btnbuy value=Details&gt; "; 
  </code></pre>