get id from select and option tag with php

Viewed 24

I am working on this problem to get product_id from user on the base of what user select the product, code is here below

$sql = "SELECT product_title,product_id FROM products";
$result = mysqli_query($conn,$sql);


echo "<select name='get_id' id='get_id' action='dropdown.php' style='width:300px;'>";
while ($row = mysqli_fetch_array($result)) {
    echo "<option value=".$row['product_id']."'" . $row['product_title'] ."'>" . $row['product_title'] ."</option>";
}

echo "</select>";
$get_id=$_REQUEST['get_id'];
echo $get_id;
mysqli_close($conn);
}

i need to save seelcted product id in get_id variable of php how can i solve this problem?

1 Answers

looks ok, whats wrong? if empty, do u have the select enclosed in a form tag? maybe this bites my eye:

echo "<option value='"
    .$row['product_id'] // only id in value quotes
    ."'>" 
    .$row['product_title'] // title tex inside tag
    ."</option>";
Related