title: AJAX code to save id value in database
body: <p><a href="https://i.stack.imgur.com/S37ee.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S37ee.png" alt="enter image description here"></a> </p>
  
  <p>I want to pass this value doctoridclickedRightNow into t_appointmentdetails table. I have made few changes to previous code using AJAX and JS as suggested on <a href="https://stackoverflow.com/questions/29374540/how-to-pass-variable-from-javascript-to-php-page-using-xmlhttp/29374838#29374838">How to Pass variable from JavaScript to PHP Page using XMLHTTP</a> . Appointment details are getting inserted into DB and I also want the doctorid of the corresponding doctor to be saved. So with the below changes I am able see the correct values being displayed when I use inspect element in mozilla. Kindly suggest me how to pass this to DB. Thanks in advance.</p>
  
  <p>
  
  <pre><code>      $sql = "SELECT doctorid, FIRST_NAME,LAST_NAME, Address, Qualification, Specialization, Consultation_Fee, Experience,image_path 
                from t_doctorprofile";
         $results = mysqli_query($db,$sql)
         or die('MySQL Error');
  
        echo '&lt;h3 style="color:#674172;margin- left:120px;float:center;display:inline-block"&gt;&lt;strong&gt;Available Dentists&lt;/strong&gt;&lt;/h3&gt;';
        while($result = mysqli_fetch_assoc($results)){
        echo '&lt;div class= "fetch" style="margin-left:120px"&gt;';
        echo "&lt;img src = 'uploads/".$result['image_path']."' width='150'  height='150'&gt;";
        echo "&lt;div id='info'&gt;";
         echo "&lt;p&gt;&lt;strong&gt;".$result['FIRST_NAME']." ".$result['LAST_NAME']."&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;";
         echo "&lt;p&gt;".$result['Qualification']."&lt;/p&gt;";
         echo "&lt;p&gt;".$result['Specialization']."&lt;/p&gt;";
         echo "&lt;p&gt;".$result['Address']."&lt;/p&gt;";
         echo "&lt;p&gt;"."&lt;b&gt;Consultation Fee-&lt;/b&gt;"." ".$result['Consultation_Fee']."&lt;/p&gt;";
         echo "&lt;p&gt;"."&lt;b&gt;Experience-&lt;/b&gt;"." ".$result['Experience']."years"." &lt;/p&gt;";   
         echo "&lt;button class='btn btn-success btn-lg' id='$result[doctorid]' data-toggle='modal' data-target='#myModal' onclick='AssignDoctorIdClicked(id)'&gt;
      Appointment&lt;/button&gt;";
         echo "&lt;script&gt;var doctoridclickedRightNow;&lt;/script&gt;"; 
         echo "&lt;/div&gt;";
         echo '&lt;form action="appointment_insert.php" method="POST"&gt;';
         echo "&lt;div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'&gt;";
         echo "&lt;div class='modal-dialog'&gt;";
         echo "&lt;div class='modal-content' style='background-color:#F1A9A0'&gt;";
         echo "&lt;div class='modal-header'&gt;";
         echo "&lt;button type='button' class='close' data-dismiss='modal' aria-hidden='true'&gt;&amp;times;&lt;/button&gt;";
         echo "&lt;h4 class='modal-title' id='myModalLabel' style='text-align:center; color:#fff'&gt;
        &lt;strong&gt;Book Appointment&lt;/strong&gt;&lt;/h4&gt;&lt;br&gt;"; 
  
     echo "&lt;/div&gt;&lt;br&gt;&lt;br&gt;";
     echo "&lt;div class='modal-body'&gt;";
  </code></pre>
  
  <p>script for AssignDoctorIdClicked function:</p>
  
  <pre><code>   &lt;script&gt;
  
       function AssignDoctorIdClicked(id) {
       console.log(id);
       var doctoridclickedRightNow = id;
       console.log(doctoridclickedRightNow);
  
      &lt;/script&gt;
  </code></pre>
  
  <p>appointment_insert.php page</p>
  
  <pre><code>if (isset($_POST["submit"])) {
      $login_user = $_SESSION['username'];
      $datetime = $_POST['datetime'];
      $info = $_POST['info'];
      $recieved_1 = $_GET['FIRST_NAME'];
  
      $query = mysqli_query($db, "INSERT INTO t_appointmentdetails (patient_name,datetime,info) VALUES ('$login_user','$datetime','$info');");
  
           $insertedDataBoolean = true;
          if($insertedDataBoolean){
      echo "Name: " . $recieved_1 . " booked successfully.";
     }
          else{
      echo "Data-insertion error.";
     }
  
  
  
      }
  </code></pre>