title: How to get sql data in html form fields using Ajax JQuery , PHP and PL SQL
body: <p>I am learning  Ajax JQuery , PHP and PL SQL.I have designed the html form given below:</p>
  
  <p><a href="https://i.stack.imgur.com/nWQHL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nWQHL.png" alt="enter image description here"></a></p>
  
  <p>Whenever,user enter a Loan ID and press Edit button, then i want to copy the query result outputs for particular Loan ID inside corresponding html from fields if that data exist,other wise print Not Exist in them.I don't know how ajax take data and distinguish them for separate form fields</p>
  
  <p>here is my front end code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
     &lt;head&gt; 
     &lt;/head&gt;
     &lt;body &gt;
        &lt;div class="container"  &gt;
           &lt;div class="panel-group"&gt;
              &lt;div class="panel panel-primary"  &gt;
                 &lt;div class="panel-heading" &gt;
                    &lt;h3 class="panel-title" style="text-align: center;"&gt;Record Loan Type Information&lt;/h3&gt;
                 &lt;/div&gt;
                 &lt;div class="panel-body"&gt;
                    &lt;form class="form-horizontal" &gt;
                       &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-sm-3"  for="acode"&gt;Loan ID:&lt;/label&gt;
                          &lt;div class="col-sm-5"&gt;
                             &lt;input type="text" class="form-control" id="textloanid" name="loanid"  placeholder="Enter Loan ID"&gt;             
                             &lt;span id="errmsg1" class="errmsg"&gt;&lt;/span&gt;
                          &lt;/div&gt;
                       &lt;/div&gt;
                       &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-sm-3" style="text-align:right;" &gt;Loan Name:&lt;/label&gt;
                          &lt;div class="col-sm-5"&gt;
                             &lt;input type="text" id="textloan_name" name="loan_name" class="form-control" placeholder="Enter Loan Name" &gt;        
                          &lt;/div&gt;
                       &lt;/div&gt;
                       &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-sm-3"  for="dcode"&gt;Description:&lt;/label&gt;
                          &lt;div class="col-sm-5"&gt;
                             &lt;input type="text" class="form-control" id="textdescription" name="description" placeholder="Enter Loan Description"&gt;               
                          &lt;/div&gt;
                       &lt;/div&gt;
                       &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-sm-3" style="text-align:right;"&gt;Amount:&lt;/label&gt;
                          &lt;div class="col-sm-5"&gt;
                             &lt;input type="text"  id="textamount" name="amount" class="form-control" placeholder="Enter Amount" &gt;        
                             &lt;span id="errmsg2" class="errmsg"&gt;&lt;/span&gt;
                          &lt;/div&gt;
                       &lt;/div&gt;
                       &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-sm-3" style="text-align:right;" &gt;Sanction Date:&lt;/label&gt;
                          &lt;div class="col-sm-5"&gt;
                             &lt;div class="input-group date"&gt;
                                &lt;span class="input-group-addon"&gt;
                                &lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
                                &lt;/span&gt;   
                                &lt;input type="text"  id='textdatetimepicker1' name="textdatetimepicker1" class="form-control" placeholder="DD/MM/YYYY"&gt;       
                             &lt;/div&gt;
                          &lt;/div&gt;
                       &lt;/div&gt;
                       &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-sm-3" style="text-align:right;"&gt;Interest Rate:&lt;/label&gt;
                          &lt;div class="col-sm-5"&gt;
                             &lt;input type="text" id="textrate" name="rate" class="form-control" placeholder="Enter Rate" &gt;       
                          &lt;/div&gt;
                       &lt;/div&gt;
                       &lt;div class="form-group"&gt;
                          &lt;div class="col-sm-offset-2 col-sm-10"&gt;
                             &lt;button type="submit" id="btnSubmit" class="btn btn-primary"&gt;Save&lt;/button&gt;
                             &lt;button type="submit" name="editbtn" class="btn btn-success editbtn"&gt;Edit&lt;/button&gt;
                             &lt;button type="button" class="btn btn-danger"&gt;Delete&lt;/button&gt;
                             &lt;button type="button" class="btn btn-info"&gt;Exit&lt;/button&gt; 
                          &lt;/div&gt;
                       &lt;/div&gt;
                    &lt;/form&gt;
                 &lt;/div&gt;
              &lt;/div&gt;
           &lt;/div&gt;
        &lt;/div&gt;
        &lt;script type="text/javascript"&gt;               
           var values = $("form").serialize();
  
           $("form").on("submit", '.editbtn', function(event) {
              event.preventDefault();
              var values = $( this ).serialize();      
              $('#serialize').text(values);  
              $.ajax({
                  url: "loan_type_info.php",
                  type: "post",
                  async:true,
                  data: values,
                  dataType: 'html',
                  contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                  success: function(data) {
                      $('#result').html((data)? data:"Empty!");
  
                  },
                  error: function(jqXHR, textStatus, errorThrown) {
                     console.log(textStatus, errorThrown);
                  }
              });
  
           });        
  
        &lt;/script&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I think,somehow i need to store query output row in php and send them to ajax.so that ajax can output them in their form fields.
  Here is my back end php code:</p>
  
  <pre><code>&lt;?php
  $loanid      = (isset($_POST['loanid'])) ? $_POST['loanid'] : "not";
  $loan_name   = (isset($_POST['loan_name'])) ? $_POST['loan_name'] : "not";
  $description = (isset($_POST['description'])) ? $_POST['description'] : "not";
  $amount      = (isset($_POST['amount'])) ? $_POST['amount'] : "not";
  $datestring  = (isset($_POST['textdatetimepicker1'])) ? $_POST['textdatetimepicker1'] : "not";
  $rate        = (isset($_POST['rate'])) ? $_POST['rate'] : "not";
  
  echo $loanid;
  echo $loan_name;
  echo $description;
  echo $amount;
  echo $rate;
  
  $date_arr = explode('/', $datestring);
  $date     = date("Y/m/d", strtotime($date_arr[2] . $date_arr[1] . $date_arr[0]));
  echo $datestring;
  echo var_dump($date);
  
  $conn = oci_connect('usr', 'pass', 'test');
  if (!$conn) {
      trigger_error("Could not connect to database", E_USER_ERROR);
  } else {
      echo "Connection established ";
  }
  $stid = oci_parse($conn, " begin  
                                 :result := PKG_PAYROLL.find_loan_type(
                                              '&lt;loan_type&gt;
                                               &lt;loan_id&gt;$loanid&lt;/loan_id&gt;                                                                                    
                                               &lt;/loan_type&gt;'
                                              );                      
  
                                  end;");
  
  oci_bind_by_name($stid, ':result', $ru, 500);
  $output = oci_execute($stid);
  echo $ru;
  
  
  ?&gt;
  </code></pre>
  
  <p>In PL SQL, i need to run query and get the data back to php.
  Here is my PL/SQL Code:</p>
  
  <pre><code> FUNCTION find_loan_type(loan_type_data NVARCHAR2 ) RETURN clob IS ret clob;
     xmlData XMLType;   
     v_code  NUMBER;
     v_errm  VARCHAR2(100);
     loan_id NUMBER(10);
     BEGIN 
     xmlData:=XMLType(loan_type_data);
     loan_id := xmlData.extract('/loan_type/loan_id/text()').getstringval();
     select * from TBL_LOAN_TYPE where LNTYPE_ID=loan_id;
     ret:=to_char(sql%rowcount);
  
  COMMIT;
  RETURN '&lt;result&gt;&lt;status affectedRow='||ret||'&gt;success&lt;/status&gt;&lt;/result&gt;';
  EXCEPTION
  WHEN OTHERS THEN
  v_code := SQLCODE;
  v_errm := SUBSTR(SQLERRM, 1, 100);
  DBMS_OUTPUT.PUT_LINE (v_code || ' ' || v_errm);
  RETURN '&lt;result&gt;&lt;status&gt;Error&lt;/status&gt; &lt;error_message&gt;'|| 'Error Message:' || v_errm ||'&lt;/error_message&gt; &lt;/result&gt;';
  END find_loan_type;
  </code></pre>
  
  <p>please help me on that.i realized that, if i can understand to exchanging data from front end to back end via ajax, php and PL SQL then, i can solve this.if you have such kind experience, then please share your knowledge.please let me know for further information.Thanks</p>