skip to Main Content
  1. I have one single inquiry form (php page) that contain a drop-down SELECT containing all products.


<select class="form-control" name="model_name" required="" id="modals">
 <option> Choose Model *</option>
  <?php
$fetch = $, com_in->prepare("SELECT * FROM main_product_tbl WHERE type='1'");
$fetch->execute();
$c = 1;
foreach ($fetch->fetchAll(PDO::FETCH_ASSOC) as $key)
{
   echo '
       <option value="' . $key['product_id'] . '">' . $key['model_name'] . '</option> ';
    $c++;
}
?>
</select>
  1. All these products have their separate/individual web pages.

Each product page has Inquiry Button, that loads the Inquiry Form (a php page)
there user has to select particular product from the drop-down SELECT.

I want that if user press the inquiry button (from any product page), it should load the Inquiry page and the respective product item should be automatically selected in the drop-down.

Kindly help.

2

Answers


  1. Pass product id or name through url and fetch value from db on inquiry page
    http://www.site.com/enquiry.php?=productid
    On enquiry page

    fetch details from database useing id or product name

    Login or Signup to reply.
  2. As first you must set a variable/cookie with the current product. In this example, it will be

    $product
    

    Then, add this code inside the <option> tag

    // We check if the product name is equal to the selected product and then select it
    if($product == $key['model_name']){echo "selected";} 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search