title: Displaying Data From A Drop Down List php
body: <p>I'm trying hard with displaying details from a selected option in a drop down list for my project.</p>
  
  <p>I have a drop down list which is populated from a MYSQLi query. I want the user to select an option and the values associated pulled from the database and displayed to the user.</p>
  
  <p>The dynamically populated drop down list is for "FirstName" of persons(Table Name) and when a user selects a name from the drop down list I want the record of that person to be to be displayed.</p>
  
  <p>The code below is for dynamically populating the drop down list. The user clicks the button and goes on the next page which should create a table with the results. There is no Error, but no result as required too.</p>
  
  <p><strong>drop down code</strong></p>
  
  <pre><code>&lt;!DOCTYPE&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;title&gt;Update Data&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;form name="form_update" method="post" action="update_test.php"&gt;
  
  &lt;?php
  $con=mysqli_connect("localhost","root","","ismat_db");
  //============== check connection
  if(mysqli_errno($con))
  {
  echo "Can't Connect to mySQL:".mysqli_connect_error();
  }
  
  
  
  //This creates the drop down box
  
  echo "&lt;select name= 'FirstName'&gt;";
  echo '&lt;option value=""&gt;'.'--- Please Select Person ---'.'&lt;/option&gt;';
  $query = mysqli_query($con,"SELECT FirstName FROM persons");
  $query_display = mysqli_query($con,"SELECT * FROM persons");
  
  while($row=mysqli_fetch_array($query))
  {
  echo "&lt;option value='". $row['id']."'&gt;".$row['FirstName']
   .'&lt;/option&gt;';
  
  }
  
  echo '&lt;/select&gt;';
  
  ?&gt;&amp;nbsp;&lt;input type="submit" name="submit" value="Submit"/&gt;
  &lt;/form&gt;&lt;br/&gt;&lt;br/&gt;
  &lt;a href="main.html"&gt; Go back to Main Page &lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>View Code</strong></p>
  
  <pre><code>&lt;title&gt;Update Data&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;!--&lt;table&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt; From Database &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
      &lt;table border="1"&gt;
          &lt;tr&gt;
              &lt;td&gt;First Name&lt;/td&gt;
              &lt;td&gt;Last Name &lt;/td&gt;
              &lt;td&gt; Gender &lt;/td&gt;
              &lt;td&gt; Subject &lt;/td&gt;
              &lt;td&gt; Hobbies &lt;/td&gt;
          &lt;/tr&gt;
       --&gt;
    &lt;?php 
  $con=mysqli_connect("localhost","root","","ismat_db");
  if(mysqli_errno($con))
  {
  echo "Can't Connect to mySQL:".mysqli_connect_error();
  }
  
  
  //$name = mysqli_real_escape_string($con,$_POST['select']);
   // $fetch = mysqli_query($con,"SELECT * FROM persons WHERE FirstName='".$name."'");
  //  $row_display=mysqli_fetch_assoc($fetch);
  
  if(isset($_POST['select']))
  {
  
  $name = mysqli_real_escape_string($con,$_POST['select']);
    $fetch = "SELECT * FROM persons WHERE FirstName = '".$name."'";
   $result = mysqli_query($con,$fetch);
  
   //display the table
   echo '&lt;table border="1"&gt;'.'&lt;tr&gt;'.'&lt;td align="center"&gt;'. 'From Database'. '&lt;/td&gt;'.'&lt;/tr&gt;';
  echo '&lt;tr&gt;'.'&lt;td&gt;'.'&lt;table border="1"&gt;'.'&lt;tr&gt;'.'&lt;td&gt;'.'First Name'.'&lt;/td&gt;'
  .'&lt;td&gt;'.'Last           Name'.'&lt;/td&gt;'.'&lt;td&gt;'. 'Gender' .'&lt;/td&gt;'.'&lt;td&gt;'
  . 'Subject'. '&lt;/td&gt;'.'&lt;td&gt;'. 'Hobbies' .'&lt;/td&gt;'.'&lt;/tr&gt;';
  while($data = mysqli_fetch_row($result))
  {
  echo ("&lt;tr&gt;&lt;td&gt;$data[0]&lt;/td&gt;&lt;td&gt;$data[1]&lt;/td&gt;&lt;td&gt;$data[2]&lt;/td&gt;&lt;td&gt;$data[3]&lt;/td&gt;&lt;td&gt;$data[4] &lt;/td&gt;&lt;/tr&gt;");
   }
  
    echo '&lt;/table&gt;'.'&lt;/td&gt;'.'&lt;/tr&gt;'.'&lt;/table&gt;';
      }
  
     ?&gt;
     &lt;!--
     &lt;/table&gt;
     &lt;/td&gt;
     &lt;/tr&gt;
     &lt;/table&gt;
     --&gt;
     &lt;br/&gt;
     &lt;a href="update.php"&gt; Go back to Main Page &lt;/a&gt;
     &lt;/body&gt;
     &lt;/html&gt;
  </code></pre>