kamal_g
asked on
Multi field selection in php
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_conne ct.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><s pan style='color:red'></span>< /label><sp an class='address'>";
echo "<select id='items' name='items' style = 'width: 546px;' onChange='get_price(this.v alue)'>";
$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</lab el></span> <span class='address'>";
}
echo "</div>";
echo "<br>";
echo "<div><label></label><span class='name'><button name = 'data' type ='button' onclick= 'valprice('items')'>Valida te value</button></span></div >";
}
?>
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_conne
//session_start();
$price = Null;
//$items = Null;
if($_POST)
{
$var1 = $_POST['country'];
$var2 = $_POST['type'];
if ($var1 != '') {
echo "<label>Item<span style='color:red'>*</span>
echo "<select id='items' name='items' style = 'width: 546px;' onChange='get_price(this.v
$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</lab
}
echo "</div>";
echo "<br>";
echo "<div><label></label><span
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To the instant question, it might be helpful to see your table schema. It looks like that code queries a database and creates an HTML document with a <select> control. This would allow a client to choose one of the <option> values. It looks like there is a JavaScript function named get_price() that will be invoked when the <select> changes. This function would need to have some knowledge of the price information that is in the database. So the complete HTML document, and the JavaScript are useful things, like your database schema, that we need to see.
If you're new to PHP and want to get a foundation in how the language works, this article can help you find good learning resources and more importantly, avoid badly written examples of obsolete or dangerous PHP code.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
In a related matter, the code here uses the MySQL extension. PHP is doing away with the MySQL extension, so you want to change to MySQLi or PDO as soon as possible. This article explains why PHP is making this change and what you must do to keep your scripts running in the future.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html