We help IT Professionals succeed at work.
Get Started

Multi field selection in php

kamal_g
kamal_g asked
on
91 Views
Last Modified: 2016-06-01
I have a product table with product code, description,selling price, cost,category etc. I have a drop down to select the product which also shows the description and the product price.
I would like to capture the product price and show/update it in a field when ever the user selects a product. on change the field should also change with the new value. How can I achieve this. I have attached my code for your kind perusal.
include('function/db_connect.php');
//session_start();
$price = Null;
//$items = Null;
if($_POST)
{
$var1 = $_POST['country'];
$var2 = $_POST['type'];
 if ($var1 != '') {        
       echo "<label>Item<span style='color:red'>*</span></label><span style='color:red'></span></label><span class='address'>";
       echo "<select id='items' name='items' style = 'width: 546px;' onChange='get_price(this.value)'>";          
       $sql = "SELECT * FROM tbl_product WHERE country_id = '$var1' AND type_id = '$var2'";  
       $db  = new DB_CONNECT();    
       $result = mysql_query($sql);
       $myarray = array();
       echo "<option value=''>Select</option>";
       while ($row = mysql_fetch_array($result)) {
            $idp = $row["product_id"];
            $iddes = $row["product_desc"];
            $selp = $row["product_sell"];
            $costp = $row["product_cost"];


       echo "<option value='" . $idp . "'>" . $iddes . "==>".$selp ."</option>";

       }
       echo "</select><label>Item</label></span><span class='address'>";

    }  
       echo "</div>";        
       echo "<br>";    



       echo "<div><label></label><span class='name'><button name = 'data'  type ='button' onclick= 'valprice('items')'>Validate value</button></span></div>";      

    }
?>
Comment
Watch Question
All-around developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE