passing id on href and submitting form on same page
<p>I am making social project form and im trying to add reply ..the reply button is a link that sends user to reply.php page with post id saved in href...on the reply.php my form action is the same page but when i click button to submit form it doesnot get the id and refreshes page with post and display error undefined id need help..</p>

<p>here is my reply.php </p>

<pre><code>&lt;?php
require('session.php');
$id=$_GET['id'];
//echo $id;


  $submit=@$_POST['submit'];
      $reply=@$_POST['reply'];


      if(isset($submit)){
           $id=@$_GET['id'];
          $sql=mysqli_query($con,"INSERT INTO REPLY (reply,Username,post_id) VALUES '$reply','$user_check','$id'");

          $sql2=mysqli_query($con,"SELECT * FROM REPLY WHERE post_id= '$id'");
          while($row=mysqli_fetch_array($sql2)){
              echo $row['Username']."&lt;br/&gt;".$row['reply']."&lt;br/&gt;";



          }



      }
else "error in submission";
?&gt;


&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;title&gt;Studhelp&lt;/title&gt;
&lt;head&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
&lt;link rel="stylesheet" href="w3.css"&gt;
&lt;link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"&gt;
 &lt;script src="bootstrap/js/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway"&gt;
&lt;link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"&gt;


&lt;?php
$sql=mysqli_query($con,"select * from posts  where post_id='$id'");
              while($row=mysqli_fetch_array($sql)){?&gt;
&lt;!-- Middle Column --&gt;
    &lt;div class="w3-col m7"&gt;

      &lt;div class="w3-row-padding"&gt;
        &lt;div class="w3-col m12"&gt;
          &lt;div class="w3-card-2 w3-round w3-white"&gt;
            &lt;div class="w3-container w3-padding"&gt;
              &lt;h3 class="w3-opacity"&gt;&lt;?php echo $row['Username'] ;?&gt;&lt;/h3&gt;
              &lt;?php 

                  echo $row['Posts']."&lt;br/&gt;".$row['date']."&lt;br/&gt;";
              }
             ?&gt;
              &lt;/p&gt;

            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
&lt;form action="reply.php" method="post"&gt;

&lt;input type="text" name="reply" &gt;
&lt;input type="submit" name="submit" value="reply"&gt;


&lt;/form&gt;
</code></pre>

<p>this is the anchor tag send id to reply.php</p>

<pre><code>&lt;a href="reply.php?id=&lt;?php echo $row['post_id']; ?&gt;" class="reply-comment"&gt; Reply &lt;/a&gt;
</code></pre>