title: I am able to inspect the hidden type variable but I am getting error of sending the input type hidden variable of HTML form to PHP file via JS
body: <p><strong>Solution:</strong></p>
  
  <pre><code>This below not worked
  
          // var user_id = $('#attach-old-campaign-form').find('[name="userid"]').val();
  
          // var added_on = $('#attach-old-campaign-form').find('[name="addedon"]').val();
  
  This below worked
  
          var lead_id = $('#attach-old-campaign-form-leadid').val();
          var user_id = $('#attach-old-campaign-form-userid').val();
          var added_on = $('#attach-old-campaign-form-addedon').val();
  
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>I am able to echo a PHP variable and also can see my variable assigned to <code>input type hidden variables</code> but when i send the HTML form with hidden type NO variable is received at JS function and also it raise error in my PHP server file <code>attach_old_campaign.php</code>.</p>
  
  <p>PIC </p>
  
  <p><a href="https://i.stack.imgur.com/WvYZQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WvYZQ.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/frdAQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/frdAQ.png" alt="enter image description here"></a></p>
  
  <p>So I have three files <code>index.html</code>, <code>attach_old_campaign.js</code> and <code>attach_old_campaign.php</code>.</p>
  
  <p>I have below part of code of <code>index.html</code>:</p>
  
  <pre><code>&lt;?php
  
                      $user_id = $_SESSION['User_Id'];
                      $lead_id = $_GET['lead_id'];
  
                      echo "User id: ".$user_id;
                      echo "Lead_Id: ".$lead_id;
  
                      if(function_exists('date_default_timezone_set')) 
                      {
  
                      date_default_timezone_set("Asia/Kolkata");
                      }   
  
                      $today = date("Y-m-d H:i:s"); 
  
                      ?&gt;
  
                     &lt;input type="hidden" name="leadid" value="&lt;?php echo $_GET['lead_id'] ?&gt;" &gt;
                     &lt;input type="hidden" name="userid" value= "&lt;?php echo $_SESSION['User_Id'] ?&gt;" &gt;                    
                     &lt;input type="hidden" name="addedon" value="&lt;?php echo date('Y-m-d H:i:s') ?&gt;" &gt;
  
  </code></pre>
  
  <p>I am getting error at above input type hidden. </p>
  
  <p>Also i am not able to console the output at my JS code file <code>attach_old_campaign.js</code>.</p>
  
  <pre><code>$(document).ready(function(){
  
      var delay = 1000;
  
      $('[name="attach_old_campaign_submit"]').click(function(e){
  
          e.preventDefault();
  
          var lead_id = $('#attach-old-campaign-form').find('[name="leadid"]').val();
  
          var campaign_arr = [];
  
          // Initializing array with Checkbox checked values
          $("input[name='checkedcampaign_arr']:checked").each(function(){
              campaign_arr.push(this.value);
          });
  
          var user_id = $('#attach-old-campaign-form').find('[name="userid"]').val();
  
          var added_on = $('#attach-old-campaign-form').find('[name="addedon"]').val();
  
          console.log(lead_id)
          console.log(user_id)
          console.log(added_on)
          console.log(campaign_arr)
  
          $.ajax({
  
              type: "POST",
              url: "./server/attach_old_campaign.php",
              data: {
                  "lead_id": lead_id,
                  "campaign_arr": campaign_arr,
                  "user_id": user_id,
                  "added_on": added_on
              }           
  
          });
  
      });
  
  });
  
  </code></pre>
  
  <p>My PHP server file <code>attach_old_campaign.php</code></p>
  
  <pre><code>&lt;?php
  
  // send a JSON encoded array to client
  
  include('../../server/connection.php');
  
  /* check connection */
  if ($conn-&gt;connect_errno) {
      printf("Connect failed: %s\n", $conn-&gt;connect_error);
      exit();
  }
  
  if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  
  
      $leadid = $_POST['lead_id'];
      $campaign_arr = $_POST['campaign_arr'];
      $userid = $_POST['user_id'];
      $addedon = $_POST['added_on'];
  
      foreach ($campaign_arr as $campaign_id) {
  
  
              $stmt = $conn-&gt;prepare("INSERT INTO `tbl_mapping_lead_and_campaign` (`Map_Lead_Id`, `Map_Campaign_Id`, `MappingAddedBy`, `MappingAddedOn`) VALUES (?,?,?,?) ");
  
              $stmt-&gt;bind_param( "ssss", $leadid, $campaign_id, $userid, $addedon ); 
  
              if($stmt-&gt;execute()){
  
                  echo "&lt;span style='color:green;'&gt;
                   Campaign information mapped to Lead successfully&lt;/span&gt;";
  
              }else{
  
                  echo "&lt;span style='color:red;'&gt; Campaign information NOT mapped to Lead..
                   &lt;/span&gt;&lt;p&gt;&lt;/p&gt;";
  
                  printf("Error: %s\n", $conn-&gt;error);
  
              }    
  
      }
  
  }else{
  
      echo "Error: %s".$conn-&gt;error;
  }
  
  ?&gt;
  
  </code></pre>