title: dynamic dropdown fetching data from database not working
body: <p>I have a table named <code>tblstationerystock</code> having three columns like :-</p>
  <p>uin,
  orderdate,
  quantity.</p>
  <p>There are multiple record on different <code>orderdate</code> against <code>uin</code>.</p>
  <p><strong>My table Structure is:-</strong></p>
  <p><a href="https://i.stack.imgur.com/o3QNq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o3QNq.jpg" alt="enter image description here" /></a></p>
  <p>i have a form in which there are two input drop down (uin and orderdate ) which takes input from table <code>tblstationerystock</code>.</p>
  <p>If i select the <code>uin</code> in the first input drop down box i want the second dropdown box should show only those <code>date</code> which belong to that particular <code>uin</code>.</p>
  <p><strong>My Problem:-</strong></p>
  <p>But the second dropdown shows all the  value all the time .</p>
  <p><strong>my code for form is</strong></p>
  <pre><code>&lt;?php
  include('includes/config.php');
  ?&gt;
  
  &lt;div class=&quot;form-group col-md-12&quot;&gt;
  &lt;label&gt; User Name&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
  &lt;select class=&quot;form-control&quot; name=&quot;user&quot; id=&quot;uin&quot; onchange=&quot;fnorderdate()&quot; &gt;
  &lt;option value=&quot;&quot;&gt; &lt;/option&gt;
  &lt;?php 
  $sql = &quot;SELECT uin from  tblstationerystock group by uin order by uin asc &quot;;
  $query = $dbh -&gt; prepare($sql);
  $query-&gt;execute();
  $results=$query-&gt;fetchAll(PDO::FETCH_OBJ);
  $cnt=1;
  if($query-&gt;rowCount() &gt; 0)
  {
  foreach($results as $result)
  {               ?&gt;  
  &lt;option value=&quot;&lt;?php echo htmlentities($result-&gt;uin);?&gt;&quot;&gt;&lt;?php echo htmlentities($result-&gt;uin);?&gt;&lt;/option&gt;
   &lt;?php }} ?&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  
  
  &lt;div class=&quot;form-group col-md-12&quot;&gt;
  &lt;label&gt; User Name&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
  &lt;select class=&quot;form-control&quot; name=&quot;user&quot; id=&quot;orderdate&quot; &gt;
  &lt;option value=&quot;&quot;&gt; &lt;/option&gt;
  &lt;?php 
  $sql = &quot;SELECT orderdate from  tblstationerystock group by orderdate order by orderdate asc &quot;;
  $query = $dbh -&gt; prepare($sql);
  $query-&gt;execute();
  $results=$query-&gt;fetchAll(PDO::FETCH_OBJ);
  $cnt=1;
  if($query-&gt;rowCount() &gt; 0)
  {
  foreach($results as $result)
  {               ?&gt;  
  &lt;option value=&quot;&lt;?php echo htmlentities($result-&gt;orderdate);?&gt;&quot;&gt;&lt;?php echo htmlentities($result-&gt;orderdate);?&gt;&lt;/option&gt;
   &lt;?php }} ?&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;script&gt;
  function fnorderdate()
  {
      uin=$('#uin').val();
      $.ajax({
          method:&quot;post&quot;,
          url:&quot;ajax.php&quot;'
          data:{uin:uin},
          
          success:function(result)
          {
              $('#orderdate').html(result);
          
          
  
  }
  &lt;/script&gt;
  </code></pre>
  <p><strong>my ajax code is</strong></p>
  <pre><code>&lt;?php
  include('includes/config.php');
  if(isset($_POST[uin]))
  {
      $uin=$POST['uin'];
      
      $select=&quot;select orderdate from tblstationerystock where uin='$uin' &quot;;
      $query=mysqli_query($conn,$select);
      while($data=mysqli_fetch_assoc($query))
      {
          echo &quot;&lt;option value='&quot;.$data['orderdate'].&quot;'&gt;&quot;.$data['orderdate'].&quot;&lt;/option&gt;
      }
  }
      
  
  
  ?&gt;
  </code></pre>