title: edit product page with id feature
body: <p>On a web app i'm making, I have an edit page which is obviously where users edit info on already existing products, it uses PHP/ MySQL. My edit page is <strong>ALMOST</strong> working exactly how I want it too. I have a drop-down populated from the SQL database, and I can edit the product info via the text-boxes. The only problem I have is that I do not know how to edit the products via the ID which changes as the products are selected.. I instead have to manually set a static value in the PHP code, I was just wondering how I could do this? I'm thinking GET could be used but not entirely sure.. I'll post pictures and code below.. thanks. </p>
  
  <p><a href="https://i.stack.imgur.com/6QW2f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6QW2f.png" alt="enter image description here"></a></p>
  
  <p>The ID changes to the corresponding product ID as I select a product from the dropdown</p>
  
  <p><a href="https://i.stack.imgur.com/YsFkZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YsFkZ.png" alt="enter image description here"></a></p>
  
  <p>As you can see I have to type in the ID in the php..</p>
  
  <p>so basically i was trying to get it to change the product to edit as i select them from the dropdown..</p>
  
  <p>hope i wasnt too confusing, thanks!
      
  
  <pre><code>$conn = new mysqli('', '', '', '') 
  or die ('Cannot connect to db');
  
  $result = $conn-&gt;query("select ID, NAME from PRODUCTS");
  
  ?&gt;&lt;div align="left"&gt;&lt;?
  print  "&lt;h3&gt;EDIT PRODUCT&lt;/h3&gt;"; 
  print "&lt;strong&gt;SELECT PRODUCT:&lt;/strong&gt;";
  print "&lt;br&gt;&lt;br&gt;";
  
  print "&lt;form method='GET' id='frm_product'&gt;";
  print   "&lt;select name='ID' OnChange='$(\"#frm_product\").submit();'&gt;";
      while ($row = $result-&gt;fetch_assoc()) 
      {
          print "&lt;option value='$row[ID]'&gt;$row[NAME]&lt;/option&gt;";
      }
  print "&lt;/select&gt;";
  print "&lt;/form&gt;";
  
  ?&gt;
  &lt;form method='POST'&gt;
  &lt;h3&gt;PRODUCT:&lt;/h3&gt;
  &lt;input type='textbox' name='product' value='&lt;?php echo $product['product'] ?     &gt;'&gt; 
  
  &lt;h3&gt;BARCODE:&lt;/h3&gt;
  &lt;input type='textbox' name='barcode' value='&lt;?php echo $product['barcode']; ?&gt;'&gt;
  
  &lt;h3&gt;TYPE:&lt;/h3&gt;
  &lt;select name="type"&gt;
      &lt;option value=""&gt;&lt;/option&gt;
      &lt;option value="A"&gt;A&lt;/option&gt; 
      &lt;option value="B"&gt;B&lt;/option&gt;
      &lt;option value="C"&gt;C&lt;/option&gt;
  &lt;/select&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;input type='submit' value='Save Changes' name=submitform&gt; 
  &lt;/form&gt;
  
  &lt;? 
  if (isset($_POST['submitform']))
  {
  $namechange = $_POST[product];
  $barcodechange = $_POST[barcode];
  $typechange = $_POST[type];
  
  $sql = "UPDATE PRODUCTS SET 
                      NAME='$namechange' 
                      ,BARCODE='$barcodechange'
                      ,TYPE='$typechange' 
                   WHERE ID='79'";
  
  if (mysqli_query($conn, $sql)) {
  echo "Record updated successfully";
  } else {
  echo "Error updating record: " . mysqli_error($conn);
  }
  mysqli_close($conn);
  }
  </code></pre>