Edward Rainden
Edward Rainden

Reputation: 35

retrieve value from drop down bar and display result

on calculatePC.php, I have this code to display the finish_product

Select product:

<select class="itemTypes">
       <?php while ($row1 = mysqli_fetch_array($result)) { ?>
           <option value="<?php echo $row1['finish_product']; ?>">
           <?php echo $row1['finish_product']; ?>
           </option>
       <?php } ?></select>
    <br/><br/>

Let's say I have chosen Table as the finish_product.

On docalculate.php, I would like to display what I've chosen based on the dropdown list I've selected.

I tried this but there is error.

<?php echo $_POST['finish_product'] ?>

May I know how to display the result?

Upvotes: 2

Views: 62

Answers (2)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72299

You need to do two things:-

  1. Create a form before select and give it an action
  2. give name attribute to your select box, then only you can get data in $_POST

So do like below:-

<form method="POST" action = "docalculate.php"> // give the php file paht in action 
<select class="itemTypes" name="finish_product"> // give name attribute to your select box
       <?php while ($row1 = mysqli_fetch_array($result)) { ?>
           <option value="<?php echo $row1['finish_product']; ?>">
           <?php echo $row1['finish_product']; ?>
           </option>
       <?php } ?></select>
    <br/><br/>
<input type ="submit" name="submit" value ="Submit">
</form>

Now on docalculate.php:-

<?php
echo "<pre/>";print_r($_POST['finish_product']); // to see value comes or not

Note:- through Jquery its also possible. Thanks

Upvotes: 0

David
David

Reputation: 218847

This doesn't exist:

$_POST['finish_product']

because you don't have a form element named "finish_product" in your markup. Add that name to the form element:

<select name="finish_product" class="itemTypes">

Upvotes: 1

Related Questions