1

enter image description here

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 How to Pass variable from JavaScript to PHP Page using XMLHTTP . 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.

      $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 '<h3 style="color:#674172;margin- left:120px;float:center;display:inline-block"><strong>Available Dentists</strong></h3>';
      while($result = mysqli_fetch_assoc($results)){
      echo '<div class= "fetch" style="margin-left:120px">';
      echo "<img src = 'uploads/".$result['image_path']."' width='150'  height='150'>";
      echo "<div id='info'>";
       echo "<p><strong>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</strong></p></div>";
       echo "<p>".$result['Qualification']."</p>";
       echo "<p>".$result['Specialization']."</p>";
       echo "<p>".$result['Address']."</p>";
       echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."</p>";
       echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"." </p>";   
       echo "<button class='btn btn-success btn-lg' id='$result[doctorid]' data-toggle='modal' data-target='#myModal' onclick='AssignDoctorIdClicked(id)'>
    Appointment</button>";
       echo "<script>var doctoridclickedRightNow;</script>"; 
       echo "</div>";
       echo '<form action="appointment_insert.php" method="POST">';
       echo "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
       echo "<div class='modal-dialog'>";
       echo "<div class='modal-content' style='background-color:#F1A9A0'>";
       echo "<div class='modal-header'>";
       echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>";
       echo "<h4 class='modal-title' id='myModalLabel' style='text-align:center; color:#fff'>
      <strong>Book Appointment</strong></h4><br>"; 

   echo "</div><br><br>";
   echo "<div class='modal-body'>";

script for AssignDoctorIdClicked function:

   <script>

     function AssignDoctorIdClicked(id) {
     console.log(id);
     var doctoridclickedRightNow = id;
     console.log(doctoridclickedRightNow);

    </script>

appointment_insert.php page

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.";
   }



    }
Community
  • 1
  • 1
jackD
  • 801
  • 2
  • 8
  • 26
  • 3
    This is too vague. You will end up asking us more and more questions once an answer is posted. Please be **super specific**. What information do you want displayed? What does the doctor database table structure look like? How are you populating the modal now? – random_user_name Jan 12 '16 at 14:35
  • As suggested I have added code about how I am saving data to mysql DB from modal form. Now along with "Thank You..." message I also want to display details of a doctor for which an appointment is booked. Doctor details contains same details present in the echo statement of class fetch. Even a suggestion would be good enough. – jackD Jan 12 '16 at 14:45
  • On a click of an appointment button that particular doctor data should be captured and should be displayed. – jackD Jan 12 '16 at 15:00
  • You have to run another mysql query to get the doctor's details. Do you have a doctor's ID and a doctor table ? – Vlad Lego Jan 12 '16 at 15:01
  • 1
    Ofcourse I do have a doctor table. Can some javascript onlick event or DOM could also play a role here? – jackD Jan 12 '16 at 15:04
  • @HebleV please try this to pass a doctor-id from JAVASCRIPT to PHP Page and the response can be displayed in any div or element you want. Visit this link: [How to pass Javascript Variable to PHP and return Response to any element](http://stackoverflow.com/questions/29374540/how-to-pass-variable-from-javascript-to-php-page/29374838#29374838) . When you are ready after passing variables then write your Logic/Query in the PHP File to get the details you want and **echo** it. – Asif Mehmood Jan 13 '16 at 07:09
  • But I don't know for which doctor the patient is going to book an appointment. So I will have to make it dynamic and how to do that? – jackD Jan 13 '16 at 07:16
  • @HebleV please UPDATE the answer at end and add explicit explaination in points: **1** What info do you have in DOM-JAVASCRIPT. **2** What do you want to display. **3** Any extra information that we are unable to understand .(Thanks) – Asif Mehmood Jan 13 '16 at 07:22
  • @Malik Asif I tried using this method http://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php wherein i created a id and tried to pass it to appointment_insert.php using POST method. Its not working and also its disturbing present doctors list display. – jackD Jan 13 '16 at 08:30
  • @HebleV , try the link in mine above comment , it passes values fine (Easiest way) Link: [How to pass Javascript Variable to PHP and return Response to any element](http://stackoverflow.com/questions/29374540/how-to-pass-variable-from-javascript-to-php-page/29374838#29374838) (Easiset way, for me) – Asif Mehmood Jan 13 '16 at 08:43
  • You are following the duplicate answer, follow the first answer of this post having ZERO VOTES You can pass your own parameters you want to pass using your own variable names. It does not crash @HebleV – Asif Mehmood Jan 13 '16 at 10:56
  • @MalikAsif I did changes to my previous code as suggested by you. but still it is not displaying doctor name. How to do it correctly. – jackD Jan 20 '16 at 06:03
  • This code has a SQL injection vulnerability. – buley Jan 20 '16 at 06:18
  • Ok I know how to get it solved but that is not my main concern right now. – jackD Jan 20 '16 at 06:20
  • Suggestions on behalf of info i have: Step1: Verify that JS variables that are to be passed (before passing to PHP file in JS function) are displayed in the console correctly. If correct, proceed. Step2: Diplay Variables (just passed by JS-PHP) by echo'ing them in PHP file. If correct, proceed. Step3: Build your logic to get the Required Doctor-list/information and manually verify the Query Result, If Query result is OK, then proceed. Step4: In PHP file, only echo the info to be displayed in a specific DIV and In jS function decide which DIV-ID_ELEMENT will be the target of OUTPUT @HebleV – Asif Mehmood Jan 20 '16 at 07:08
  • If you have trouble in the the above comment **STEPS** , you can ask. This will be the best option to clear the intent/problem being faced by you Mr. @HebleV – Asif Mehmood Jan 20 '16 at 07:11
  • Or you can tell me to perform the **STEPS** . I am available for this. You will just have to hang around. Upto you @HebleV – Asif Mehmood Jan 20 '16 at 07:27
  • I am trying but am getting errors. So am ready to hang around. Could you please help me with an answer? – jackD Jan 20 '16 at 08:04
  • Visit this link: [LINK](http://chat.stackoverflow.com/) and after that i'll be able to chat with you @HebleV – Asif Mehmood Jan 20 '16 at 09:14
  • Have sent you the message. – jackD Jan 20 '16 at 09:38
  • 1
    Yes got it. Good luck! @HebleV http://chat.stackoverflow.com/rooms/101164/pass-js-to-php-and-display-data-in-div – Asif Mehmood Jan 25 '16 at 19:29

0 Answers0