title: Display result in dropdown and select to perform query in php mysql
body: <p>I have a database named Data which has a table in which their are different names of products their id and prices, i want to make a web page using php so that i can edit,add and save the items from the web page to the DB and search the names accordingly.</p>
  
  <pre><code>  &lt;html&gt;
    &lt;head&gt;
   &lt;title&gt;Products store&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;p  style="font-size:20px" align="center"&gt; &lt;b&gt;Product Database Editor&lt;/b&gt; &lt;/p&gt;
    &lt;p&gt;
    &lt;form method="post"&gt;
     Enter Product Name: &lt;input type="text" name="pname" id="pname" size="70"&gt;
   &lt;input type="submit"&gt;
    &lt;/p&gt;
   &lt;form method="post"&gt;
  &lt;select id="opt" name="opt"&gt;
     &lt;?php
  $pname = $_REQUEST['pname'];
  
  // $pname= mysql_real_escape_string($_POST['pname']);
  
   $con = mysql_connect("localhost","root","");
   if (!$con)
      {
       die('Could not connect: ' . mysql_error());
        }
       mysql_select_db("Dataentry", $con);
  
        $result = mysql_query("SELECT * FROM products where name like '%$pname%'");
        $result_rows = mysql_num_rows($result);
  
        if($pname==NULL)
          {
          echo "Please enter a product name!";
            }
        else if($result_rows==0)
          {
        echo "Product Name does not exist!";
          }
       else
          {
          while($row = mysql_fetch_array($result))
           {
  
       $name = $row['name'];
  
       echo "&lt;option value='$name_selected'&gt;$name&lt;/option&gt;";
  
     //echo ("&lt;option value = '" . $row['name'] . "'&gt;" . $row['id'] . "&lt;/option&gt;");
  
        echo $name_selected;  
  
  
   echo "&lt;br /&gt;";
   }
   }
   mysql_close($con);
  
  
    ?&gt;
   &lt;/select&gt;
    &lt;/form&gt;
  
    &lt;/body&gt;
     &lt;/html&gt; 
  </code></pre>
  
  <p>when i run this code i get the names list in the dropdown but after i select any name, nothing happens, how should i modify my code so that i can select any name from the dropdown and then be able to fetch the price of that particular name to edit it.
  please help, coding will be much helpful. </p>