title: Reading data not working in CRUD style table. PHP Ajax, SQL Server
body: <p>I am trying to implement a table that I can dynamically add data into with ajax, I have the insert working and it's going into my database fine, but I can seem to get the data to display on the page.</p>
  
  <p>These are my ajax functions:</p>
  
  <pre><code>&lt;script&gt;
      function saveData(){
      var qid = '25';
      var ccode = '0123';
      var pname = $('#prodName').val();
      var pcode = $('#prodCode').val();
      var banda = $('#bandA').val();
      var nprice = $('#newPrice').val();
      $.ajax({
          type: "POST",
          url: "quote2.php?p=add",
          data: "prodName="+pname+"&amp;prodCode="+pcode+"&amp;bandA="+banda+"&amp;newPrice="+nprice,
          success: function(data){
              viewData();
          }
      });
      }
      function viewData(){
          $.ajax({
              type: "GET",
              url: "quote2.php",
              success: function(data){
                  $('tbody').html(data);
              }
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>This is my php script:</p>
  
  <pre><code>&lt;?php 
      $page = isset($_GET['p'])?$_GET['p']:'';
      if($page == 'add'){
          $quoteID = '25';
          $customerCode = '0123';
          $productCode = $_POST['prodCode'];
          $productName = $_POST['prodName'];        
          $bandA = $_POST['bandA'];
          $nprice = $_POST['newPrice'];
  
          $query = "INSERT INTO po_special_price_products (QuoteID, CardCode, SlpCode, SlpName, BandA, NewPrice) 
                              VALUES ('$quoteID', '$customerCode', '$productCode', '$productName', '$bandA', '$nprice')"; 
          $stmt = sqlsrv_prepare($sapconn2, $query); 
          if (sqlsrv_execute($stmt) === false) { 
              die(print_r(sqlsrv_errors(), true)); 
          } 
      }else{
          $query = "SELECT * FROM po_special_price_products WHERE QuoteID = '$quoteID'"; 
          $stmt = sqlsrv_prepare($sapconn2, $query);
          $result = sqlsrv_execute($stmt);
          while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
      ?&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;?php echo $row['ID'];?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row['QuoteID'];?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row['CardCode'];?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row['SlpCode'];?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row['SlpName'];?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row['BandA'];?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row['NewPrice'];?&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;button&gt;edit&lt;/button&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php } 
      }
  ?&gt;
  </code></pre>
  
  <p>But when I load the page the table is empty, can anyone help?</p>