title: Sending php variable within onclick function argument in HTML not working within a loop
body: <p>Let me know where I'm wrong. I've been trying to send php variable within a onclick function argument but its not working. The argument is passed in InsertReply function.
  Here is the code:</p>
  
  <pre><code>$sql22 = "SELECT * FROM comments WHERE PostID=$id";
  $count22=$conect-&gt;query($sql22);
  if($count22-&gt;num_rows&gt;0){               //If comments exist
  while($row = $count22-&gt;fetch_array()){      //Fetching Comments
      $mail = $row['UserMail'];
      $comment = $row['Comment'];
      $comment_id = $row['ID'];
       echo "&lt;br&gt;";
       echo "&lt;p&gt;".$comment_id."&lt;/p&gt;";
      // Reply input field starts 
      ?&gt;
       &lt;input type='text' name='reply' id='reply' placeholder='Enter Reply here' min='5' max='100' class='big-input' style='width:40%;margin-left:40px;margin-right:40px;'&gt;
   &lt;?php
                      echo "&lt;input type='hidden' name='mail' id='mail' value= '".$current_user."'/&gt;";
                      echo "&lt;input type='hidden' name='postid' id='postid' value= '".$id."'/&gt;";
  echo "&lt;button class='btn btn-outline-info' onclick='InsertReply(&lt;?php echo $comment_id ?&gt;)'&gt;Reply&lt;/button&gt;";
  }       
  }
  </code></pre>
  
  <p>Here is the InsertReply Function:</p>
  
  <pre><code>function InsertReply(x) {
  alert("Insert Reply Function Called! with comment id : " + x);
  //Storing values in variables
  var reply = document.getElementById("reply").value; 
  var mail = document.getElementById("mail").value;
  var p_id = document.getElementById("postid").value;
  alert("Reply is "+reply);
  
  alert("Reply will be added with Reply : " + reply + ", by : "+ mail + ", Post ID : " + p_id + " &amp; Comment ID : "+x);
  </code></pre>
  
  <p>I know there are lots of issues with the code. Please guide me as I'm badly stuck. Let me know if anything else is required. I just want to send variable value to the InsertReply function. Any alternate method or suggestion will be highly appreciated.</p>