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 ALMOST 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.
The ID changes to the corresponding product ID as I select a product from the dropdown
As you can see I have to type in the ID in the php..
so basically i was trying to get it to change the product to edit as i select them from the dropdown..
hope i wasnt too confusing, thanks!
$conn = new mysqli('', '', '', '')
or die ('Cannot connect to db');
$result = $conn->query("select ID, NAME from PRODUCTS");
?><div align="left"><?
print "<h3>EDIT PRODUCT</h3>";
print "<strong>SELECT PRODUCT:</strong>";
print "<br><br>";
print "<form method='GET' id='frm_product'>";
print "<select name='ID' OnChange='$(\"#frm_product\").submit();'>";
while ($row = $result->fetch_assoc())
{
print "<option value='$row[ID]'>$row[NAME]</option>";
}
print "</select>";
print "</form>";
?>
<form method='POST'>
<h3>PRODUCT:</h3>
<input type='textbox' name='product' value='<?php echo $product['product'] ? >'>
<h3>BARCODE:</h3>
<input type='textbox' name='barcode' value='<?php echo $product['barcode']; ?>'>
<h3>TYPE:</h3>
<select name="type">
<option value=""></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<br><br>
<input type='submit' value='Save Changes' name=submitform>
</form>
<?
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);
}