creating a Session variable in onclick() event of PHP submit button
===

I created a form and have gone through a [similar question][1] on Stackoverflow as well, relating to this area of sending a variable from one page to another. 

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.

    <form name="send" method="POST" action="got.php">
     <hidden id="value" name="value"/>
    //<input type="text" id="value">
    //<input type="hidden" name="myVariable" value="'.  htmlentities("myVariable").'">;
    <input type=submit name=submit value="submit"  onclick="<?php session_start(); $_SESSION(this.id) ?>">
    </form>


  [1]: http://stackoverflow.com/questions/8524310/set-a-variable-in-session-when-the-submit-button-is-clicked-in-struts

The full code is given below,

    echo "<form name=payment action='properties_details.php'>";
    echo "Results <br>";
    while ($row= mysql_fetch_array($result)) {
    echo " <table border=3 cell padding=1> <tr> <td> ";
    
    $id=$row['id'];
    $pid=$row['pref'];
    //And the remaining values as well		
    
    //<input type="hidden" name="myVariable" value="'.  htmlentities($pid).'">;
    //<input type="hidden" name="myVariable" value="'.  $pid.'">;
    
    echo "<p>Property ID &nbsp".$pid;
    echo "<br> <p> Name &nbsp";
    echo $row["name"];
    echo "<br>  Properties &nbsp";
    echo $row["catergory"];
    // And printing the remaining values
    
    echo "<input type=submit name=btnbuy value=Details> "; 

